Chat Completions
Generate conversational responses using Claude models through the same unified chat completions endpoint you use for every other provider.
POST
/v1/chat/completionsSame endpoint, no translation needed
Send an OpenAI-style request body with a Claude model name. The gateway routes it to Anthropic and returns an OpenAI-style response, so you don't need to learn the native Messages API or handle Anthropic's response shape separately.
Supported Models
| Model | Provider | Description |
|---|---|---|
claude-3-5-sonnet-latest | Anthropic | Best balance of intelligence and speed |
claude-3-5-haiku-latest | Anthropic | Fastest, most cost-effective Claude model |
claude-3-opus-20240229 | Anthropic | Highest intelligence for complex tasks |
Request
Body Parameters
modelstringrequiredModel ID — e.g. "claude-3-5-sonnet-latest"
messagesarrayrequiredArray of message objects with role and content
temperaturenumberSampling temperature (0-1)
Default: 1
max_tokensintegerMaximum tokens to generate
Default: 1024
top_pnumberNucleus sampling parameter
Default: 1
streambooleanEnable server-sent events streaming
Default: false
stopstring | string[]Stop sequences to halt generation
toolsarrayList of tools (functions) the model can call
tool_choicestring | objectControl tool selection behavior
Options: auto, none, required
cURL
curl https://api.metriqual.com/v1/chat/completions \
-H "Authorization: Bearer mql_your_key" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-3-5-sonnet-latest",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is quantum computing?"}
],
"temperature": 0.7,
"max_tokens": 500
}'TypeScript SDK
const response = await mql.chat.create({
model: 'claude-3-5-sonnet-latest',
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'What is quantum computing?' }
],
temperature: 0.7,
max_tokens: 500
});
console.log(response.choices[0].message.content);Python SDK
response = mql.chat.create(
model="claude-3-5-sonnet-latest",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is quantum computing?"},
],
temperature=0.7,
max_tokens=500,
)
print(response["choices"][0]["message"]["content"])Response
Response Fields
idstringUnique completion ID
objectstringAlways "chat.completion"
createdintegerUnix timestamp
modelstringModel used for completion
choicesarrayArray of completion choices
usageobjectToken usage statistics
200
{
"id": "chatcmpl-claude-abc123",
"object": "chat.completion",
"created": 1705320000,
"model": "claude-3-5-sonnet-latest",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Quantum computing is a type of computation..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 25,
"completion_tokens": 150,
"total_tokens": 175
}
}Streaming
Set stream: true to receive incremental responses via Server-Sent Events.
TypeScript SDK Streaming
// Using async iterator
for await (const chunk of mql.chat.stream({
model: 'claude-3-5-sonnet-latest',
messages: [{ role: 'user', content: 'Tell me a story' }]
})) {
process.stdout.write(chunk.choices[0]?.delta?.content || '');
}Python SDK Streaming
for chunk in mql.chat.stream(
model="claude-3-5-sonnet-latest",
messages=[{"role": "user", "content": "Tell me a story"}],
):
print(chunk["choices"][0]["delta"].get("content", ""), end="")