ChatCompletions Format
Create a model response from conversation history. Supports streaming and non-streaming. Compatible with OpenAI Chat Completions API.
Note: Full path: POST /v1/chat/completions. OpenAI SDK base_url must include /v1.Supports usage.include (cost in the response), models (fallback sequence) and provider.sort (routing preference); see the request body below.
Example model
Examples below use gpt-4 (GPT-4). Replace model and adjust size, quality, etc. per console docs when switching models.
Create chat completion
POST
https://token.easyapi.com/v1/chat/completionsCreate a model response from conversation history. Compatible with OpenAI Chat Completions API; supports streaming and non-streaming.
Request parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
Authorization | header | string | Yes | EasyAPI API Key. Format: Bearer `API_KEY` |
Content-Type | header | string | Yes | Request body format |
Request body
| Name | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model ID |
messages | array<object> | Yes | Conversation message list |
temperature | number | No | Sampling temperature, default 1, range 0–2 |
top_p | number | No | Nucleus sampling, default 1, range 0–1 |
n | integer | No | Number of completions, default 1, must be ≥ 1 |
stream | boolean | No | Stream responses, default false |
stream_options | object | No | Extra options for streaming |
stop | string | array<string> | No | Stop sequence(s), string or string array |
max_tokens | integer | No | Max tokens to generate |
max_completion_tokens | integer | No | Max completion tokens |
presence_penalty | number | No | Presence penalty, default 0, range -2–2 |
frequency_penalty | number | No | Frequency penalty, default 0, range -2–2 |
logit_bias | object | No | Bias specific token probabilities |
user | string | No | End-user identifier for abuse monitoring |
tools | array<object> | No | Tool definitions the model may call |
tool_choice | string | object | No | Tool choice strategy, string or object |
response_format | object | No | Response format, e.g. JSON Schema |
seed | integer | No | Seed for best-effort reproducibility |
reasoning_effort | string | No | medium |
modalities | array<string> | No | Output modalities, e.g. text, audio |
audio | object | No | Audio output configuration |
usage | object | No | Set usage.include = true to add a cost field (USD for this request) to the usage object; for streaming it arrives in the final chunk that carries usage. The final charge is reported by GET /v1/generation |
models | array<string> | No | Fallback model sequence (up to 5). When the primary model has no available channel, or the upstream fails before any output is sent, the next model is tried in order; limited to models this key may use |
provider | object | No | Routing preference within the same priority tier: provider.sort = price picks the cheapest channel; latency picks the lowest measured time-to-first-token (end-to-end latency for non-streaming); throughput picks the highest measured output tokens/s. latency and throughput use live measurements of this model on each channel and fall back to channel health-check timing when no measurements exist. The model suffix :floor equals sort=price and :nitro equals sort=throughput |
Example
{
"model": "gpt-4",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Hello!"
}
],
"temperature": 0.7,
"stream": false,
"usage": {
"include": true
}
}Response example
{
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1718452800,
"model": "gpt-4",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! How can I help you today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 20,
"completion_tokens": 12,
"total_tokens": 32,
"prompt_tokens_details": {
"cached_tokens": 0,
"text_tokens": 20,
"audio_tokens": 0,
"image_tokens": 0
},
"completion_tokens_details": {
"text_tokens": 12,
"audio_tokens": 0,
"reasoning_tokens": 0
},
"cost": 0.000124
},
"system_fingerprint": "fp_abc123"
}