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
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
}
}claude-3-5-sonnet-20241022.role and 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 to receive responses as they’re generated:
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
ID of the model to use
"gpt-3.5-turbo"
A list of messages comprising the conversation so far
Show child attributes
If set, partial message deltas will be sent
Sampling temperature between 0 and 2
0 <= x <= 2The maximum number of tokens to generate
Nucleus sampling parameter
How many completions to generate
Up to 4 sequences where the API will stop generating
Penalize new tokens based on presence in text
-2 <= x <= 2Penalize new tokens based on frequency in text
-2 <= x <= 2