Create Chat Completion
/v1/chat/completionsCreates a completion for the chat message
On this page
Request Body
Parameter model
ID of the model to use. View available models in Console or with GET /v1/models.
Parameter messages
A list of messages comprising the conversation.
Each message object contains:
role(string):system,user, orassistantcontent(string | array): The message content
When content is an array, AnyPath supports structured multimodal blocks for compatible models:
- text:
{ "type": "text", "text": "..." } - image:
{ "type": "image_url", "image_url": { "url": "https://..." } }
For multimodal production traffic, prefer public https URLs.
Parameter temperature
Sampling temperature between 0 and 2. Higher values make output more random.
Parameter max_tokens
Maximum number of tokens to generate.
Parameter stream
If true, partial message deltas will be sent as SSE events.
Parameter stream_options
Options for streaming. Set include_usage: true to receive token usage in stream chunks.
Parameter top_p
Nucleus sampling parameter. We recommend altering this or temperature, not both.
Parameter frequency_penalty
Number between -2.0 and 2.0. Positive values penalize repeated tokens.
Parameter presence_penalty
Number between -2.0 and 2.0. Positive values penalize tokens already in the text.
Parameter stop
Up to 4 sequences where the API will stop generating tokens.
Parameter tools
A list of tools the model may call (function calling).
Parameter tool_choice
Controls how the model uses tools. Options: auto, none, required, or a specific tool object.
Parameter parallel_tool_calls
Whether to enable parallel function calling. Set to false to call functions sequentially.
Parameter max_completion_tokens
Maximum tokens for the completion. Alternative to max_tokens, useful for newer reasoning-enabled model families.
Parameter reasoning_effort
Reasoning effort for reasoning-enabled models. Options: low, medium, high.
Parameter seed
Random seed for deterministic sampling.
Parameter n
Number of completions to generate (1-128).
Parameter logprobs
Whether to return log probabilities.
Parameter top_logprobs
Number of top log probabilities to return (0-20). Requires logprobs: true.
Parameter top_k
Top-K sampling parameter (for Anthropic/Gemini models).
Parameter response_format
Response format specification. Use {"type": "json_object"} for JSON mode. Treat {"type": "json_schema", "json_schema": {...}} as a best-effort path that depends on the selected model and routed behavior.
Parameter logit_bias
Modify the likelihood of specified tokens appearing. Map token IDs (as strings) to bias values from -100 to 100.
Parameter user
A unique identifier representing your end-user for abuse monitoring.
Response
Response Field id
Unique identifier for the completion.
Response Field object
Always chat.completion.
Response Field created
Unix timestamp of when the completion was created.
Response Field model
The model used for completion.
Response Field choices
List of completion choices.
Each choice contains:
index(integer): Index of the choicemessage(object): The generated messagefinish_reason(string): Why the model stopped (stop,length,tool_calls)
Response Field usage
Token usage statistics.
prompt_tokens(integer): Tokens in the promptcompletion_tokens(integer): Tokens in the completiontotal_tokens(integer): Total tokens used
Request Example
curl -X POST "https://api.anypath.dev/v1/chat/completions" \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-mini",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
],
"temperature": 0.7,
"max_tokens": 1000
}'
from openai import OpenAI
client = OpenAI(
api_key="sk-your-api-key",
base_url="https://api.anypath.dev/v1"
)
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
],
temperature=0.7,
max_tokens=1000
)
print(response.choices[0].message.content)
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: 'sk-your-api-key',
baseURL: 'https://api.anypath.dev/v1'
});
const response = await client.chat.completions.create({
model: 'gpt-4o-mini',
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'Hello!' }
],
temperature: 0.7,
max_tokens: 1000
});
console.log(response.choices[0].message.content);
<?php
$ch = curl_init('https://api.anypath.dev/v1/chat/completions');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'Authorization: Bearer sk-your-api-key'
],
CURLOPT_POSTFIELDS => json_encode([
'model' => 'gpt-4o-mini',
'messages' => [
['role' => 'system', 'content' => 'You are a helpful assistant.'],
['role' => 'user', 'content' => 'Hello!']
],
'temperature' => 0.7,
'max_tokens' => 1000
])
]);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
echo $data['choices'][0]['message']['content'];
Multimodal Example
{
"model": "gemini-2.5-pro",
"messages": [
{
"role": "user",
"content": [
{ "type": "text", "text": "Describe this image briefly." },
{ "type": "image_url", "image_url": { "url": "https://example.com/demo.jpg" } }
]
}
],
"max_tokens": 64
}
Response Example
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1706000000,
"model": "gpt-4o-mini",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! How can I help you today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 20,
"completion_tokens": 9,
"total_tokens": 29
}
}
Error Response Example
Insufficient shared-route balance or a provider-side error returns a standard error body:
{
"error": {
"message": "API key spending limit exceeded.",
"type": "spending_limit_exceeded",
"code": "spending_limit_exceeded"
}
}
{
"error": {
"message": "Upstream provider returned an error.",
"type": "provider_error",
"code": "provider_error"
}
}
At runtime type is always identical to code; both carry the canonical code from the Error Codes registry.
Always check error.code over the HTTP status alone — it distinguishes caller‑fixable errors (invalid model, over‑limit) from transient provider errors.