cURL
curl --request POST \ --url https://api.xtrix.workers.dev/v1/chat/completions \ --header 'Authorization: Bearer <token>' \ --header 'Content-Type: application/json' \ --data '{ "model": "gpt-3.5-turbo", "messages": [ { "role": "system", "content": "<string>" } ] }'
{ "id": "<string>", "object": "chat.completion", "created": 123, "model": "<string>", "choices": [ { "index": 123, "message": { "role": "system", "content": "<string>" }, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 123, "completion_tokens": 123, "total_tokens": 123 } }
Create a chat completion
claude-3-5-sonnet-20241022
role
content
curl https://api.xtrix.workers.dev/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_KEY" \ -d '{ "model": "claude-3-5-sonnet-20241022", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'
{ "id": "chatcmpl-abc123", "object": "chat.completion", "created": 1677858242, "model": "claude-3-5-sonnet-20241022", "system_fingerprint": "fp_44709d6f", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "The capital of France is Paris." }, "logprobs": null, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 10, "completion_tokens": 8, "total_tokens": 18 } }
stream: true
const stream = await openai.chat.completions.create({ model: 'claude-3-5-sonnet-20241022', messages: [{ role: 'user', content: 'Tell me a story' }], stream: true, }); for await (const chunk of stream) { process.stdout.write(chunk.choices[0]?.delta?.content || ''); }
{ "id": "chatcmpl-abc123", "object": "chat.completion.chunk", "created": 1677858242, "model": "claude-3-5-sonnet-20241022", "system_fingerprint": "fp_44709d6f", "choices": [ { "index": 0, "delta": { "content": "The" }, "logprobs": null, "finish_reason": null } ] }
{ "id": "chatcmpl-abc123", "object": "chat.completion.chunk", "created": 1677858242, "model": "claude-3-5-sonnet-20241022", "system_fingerprint": "fp_44709d6f", "choices": [ { "index": 0, "delta": {}, "logprobs": null, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 10, "completion_tokens": 25, "total_tokens": 35 } }
data: [DONE]
API key authentication
Successful response
The response is of type object.
object