Chat Completions
Create Chat Completion
Creates a chat completion using conversational messages. Supports tool calling, image inputs, and multiple AI providers with automatic fallbacks.
post/v1/chat/completions
Request body
Example request
{
"model": "openai/gpt-4o-mini",
"messages": [
{
"role": "user",
"content": "Hello, how are you?",
"tool_calls": [
{
"id": "tool_123",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"location\": \"San Francisco, CA\"}"
}
}
]
}
],
"max_tokens": 1000,
"fallbacks": [
"anthropic/claude-3-sonnet-20240229",
"openai/gpt-4o"
]
}Response
Successful chat completion
Example response
{
"id": "chatcmpl-123",
"object": "chat.completion",
"choices": [
{
"message": {
"role": "user",
"content": "Hello, how are you?",
"tool_calls": [
{
"id": "tool_123",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"location\": \"San Francisco, CA\"}"
}
}
]
},
"finish_reason": "stop",
"log_probs": {
"content": [
{
"logprob": -0.123,
"token": "hello",
"top_logprobs": [
{
"logprob": -0.456,
"token": "world"
}
]
}
],
"refusal": [
{
"logprob": -0.456,
"token": "world"
}
]
}
}
],
"model": "gpt-4o",
"created": 1677652288,
"usage": {
"prompt_tokens": 56,
"completion_tokens": 31,
"total_tokens": 87
},
"extra_fields": {
"provider": "openai",
"model_params": {
"temperature": 0.7,
"top_p": 0.9,
"top_k": 40,
"max_tokens": 1000,
"stop_sequences": [
"\n\n",
"END"
],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current weather for a location",
"parameters": {
"type": "object"
}
}
}
],
"tool_choice": {
"type": "auto",
"function": {
"name": "get_weather"
}
},
"parallel_tool_calls": true
},
"latency": 1.234,
"chat_history": [
{
"role": "user",
"content": "Hello, how are you?",
"tool_calls": [
{
"id": "tool_123",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"location\": \"San Francisco, CA\"}"
}
}
]
}
]
}
}