POST /v1/chat/completions
OpenAI-compatible chat completions with streaming, tools, vision, and model aliases.
POST /v1/chat/completions
Request
curl https://api.model-gate.com/v1/chat/completions \
-H "Authorization: Bearer mg_live_..." \
-H "Content-Type: application/json" \
-d '{
"model": "ch-47",
"messages": [
{"role": "user", "content": "Explain this API in one sentence."}
],
"stream": false
}'
The model can be a canonical ID or an enabled alias. Model Gate resolves aliases before pricing and sends the canonical ID upstream.
Response
{
"id": "chatcmpl_example",
"object": "chat.completion",
"model": "claude-opus-4.7",
"choices": [
{
"index": 0,
"message": {"role": "assistant", "content": "Model Gate provides one compatible API for multiple AI models."},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 14,
"completion_tokens": 17,
"total_tokens": 31
}
}
Streaming request
Set "stream": true. The upstream Server-Sent Events are passed through without rewriting successful event payloads.
Asynchronous request
For supported endpoints, add "async": true with "stream": false. The immediate response is HTTP 202 and contains request_id and a Partner API result URL.
Errors
Provider non-2xx status, body, and content type are passed through unchanged. Locally generated validation errors use the Model Gate error envelope.
| Status | Meaning | Action |
|---|---|---|
400 | Invalid request | Check the request body and model ID. |
401 | Invalid or frozen key | Verify or rotate the API key. |
429 | Rate or concurrency limit exceeded | Respect Retry-After and retry with backoff. |
5xx | Temporary upstream or gateway error | Retry idempotent requests with exponential backoff. |