Chat Completions
code
POST /api/v1/chat/completionsThe core endpoint. Send a conversation and receive a model response. Fully compatible with the OpenAI Chat Completions schema.
Request body
| Field | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model ID, e.g. anthropic/claude-sonnet-4 |
messages | array | Yes | Array of {role, content} objects |
stream | boolean | No | Return SSE stream instead of JSON |
temperature | number | No | 0–2, default varies by model |
max_tokens | number | No | Max tokens to generate, up to 64,000 |
You can browse all available models and their exact parameter support on the [Models](/models) page.
Example request
bash
curl https://modelgates.ai/api/v1/chat/completions \ -H "Authorization: Bearer sk-mg-YOUR_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "openai/gpt-4o", "messages": [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Explain quantum computing in one sentence."} ], "temperature": 0.7, "max_tokens": 256 }'Example response
json
{ "id": "gen-xxxxxxxx", "object": "chat.completion", "created": 1715424000, "model": "openai/gpt-4o", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "Quantum computing uses quantum bits to perform calculations..." }, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 24, "completion_tokens": 18, "total_tokens": 42 }}Streaming
Set stream: true to receive Server-Sent Events (SSE). Each chunk contains a partial delta message.
Streaming is recommended for real-time UIs. The total cost is computed after the stream ends and debited from your balance.