Chat Completions
POST /v1/chat/completions
Send chat messages to any of 200+ models and receive completions, with support for streaming, tool calling, vision, and structured output.
Request
POST https://api.chuizi.ai/v1/chat/completions
Authentication
Authorization: Bearer ck-your-api-key
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
model | string | Yes | — | Model name, e.g. anthropic/claude-sonnet-4-6, openai/gpt-4.1 |
messages | array | Yes | — | Array of messages (max 2048) |
max_tokens | integer | No | Model default | Maximum tokens to generate, 1-1,000,000 |
stream | boolean | No | false | Enable SSE streaming output |
Message Format
config.json
json
{ "role": "system" | "user" | "assistant" | "tool" | "developer", "content": "string or content parts array", "name": "optional sender name", "tool_calls": [{ "id": "...", "type": "function", "function": { "name": "...", "arguments": "..." } }], "tool_call_id": "corresponding tool_call ID (required when role=tool)" }
Request Example
config.json
json
{ "model": "anthropic/claude-sonnet-4-6", "messages": [ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "Explain the basics of quantum computing." } ], "max_tokens": 1024, "temperature": 0.7 }
Response
Non-Streaming Response
config.json
json
{ "id": "gen-xxxxxxxxxxxxxxxx", "object": "chat.completion", "created": 1712000000, "model": "anthropic/claude-sonnet-4-6", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "Quantum computing leverages the principles of quantum mechanics..." }, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 24, "completion_tokens": 150, "total_tokens": 174, "prompt_tokens_details": { "cached_tokens": 0, "cache_creation_tokens": 0 } }, "x_chuizi": { "generation_id": "gen-xxxxxxxxxxxxxxxx", "latency_ms": 1200, "cost": "0.00057600" } }
Code Examples
terminal
bash
curl -X POST https://api.chuizi.ai/v1/chat/completions \ -H "Authorization: Bearer ck-your-key" \ -H "Content-Type: application/json" \ -d '{ "model": "anthropic/claude-sonnet-4-6", "messages": [{"role": "user", "content": "Hello!"}], "max_tokens": 100 }'
Next Steps
- Streaming Guide — implement token-by-token streaming responses
- Function Calling — let models invoke your tools and APIs
- Structured Output — get JSON responses matching your schema
- Error Handling — handle errors and retries in production