Skip to main content

Chat Completions API

The Chat Completions API is the primary interface for conversational interactions with language models through Conduit. It follows the OpenAI chat completions format.

Endpoint

POST /v1/chat/completions

Request Parameters

ParameterTypeRequiredDescription
modelstringYesThe ID of the model to use (your configured virtual model name)
messagesarrayYesArray of message objects with role and content
temperaturenumberNoControls randomness (0-2, default 1)
top_pnumberNoControls diversity via nucleus sampling (0-1, default 1)
nintegerNoNumber of completions to generate (default 1)
streambooleanNoStream partial results as they're generated (default false)
stopstring/arrayNoSequence(s) where the API will stop generating
max_tokensintegerNoMaximum number of tokens to generate
presence_penaltynumberNoPenalty for new tokens based on presence in context (-2 to 2)
frequency_penaltynumberNoPenalty for new tokens based on frequency in context (-2 to 2)
logit_biasobjectNoModify likelihood of specified tokens
userstringNoUnique identifier for the end-user
toolsarrayNoList of tools the model may call
tool_choicestring/objectNoControls how the model calls tools
response_formatobjectNoFormat of the response (eg. JSON mode)
seedintegerNoSeed for deterministic outputs
cache_controlobjectNoControl caching behavior
routingobjectNoCustom routing options for this request

Basic Example

curl http://localhost:5000/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer condt_your_virtual_key" \
-d '{
"model": "my-gpt4",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
]
}'

Response Format

{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1677858242,
"model": "my-gpt4",
"choices": [
{
"message": {
"role": "assistant",
"content": "Hello! How can I help you today?"
},
"finish_reason": "stop",
"index": 0
}
],
"usage": {
"prompt_tokens": 18,
"completion_tokens": 8,
"total_tokens": 26
}
}

Streaming Example

curl http://localhost:5000/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer condt_your_virtual_key" \
-d '{
"model": "my-gpt4",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
],
"stream": true
}'

Multimodal Example

curl http://localhost:5000/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer condt_your_virtual_key" \
-d '{
"model": "my-vision-model",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "What is in this image?"
},
{
"type": "image_url",
"image_url": {
"url": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAA..."
}
}
]
}
]
}'

Tool Calling Example

curl http://localhost:5000/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer condt_your_virtual_key" \
-d '{
"model": "my-gpt4",
"messages": [
{"role": "user", "content": "What is the weather in San Francisco?"}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"]
}
},
"required": ["location"]
}
}
}
]
}'

Conduit-Specific Extensions

Cache Control

Control the caching behavior for this specific request:

{
"model": "my-gpt4",
"messages": [...],
"cache_control": {
"no_cache": false,
"ttl": 7200
}
}

Custom Routing

Override the default routing strategy for this specific request:

{
"model": "my-gpt4",
"messages": [...],
"routing": {
"strategy": "least_cost",
"fallback_enabled": true,
"provider_override": "anthropic"
}
}

Error Codes

HTTP CodeError TypeDescription
400invalid_request_errorThe request was malformed
401authentication_errorInvalid or missing API key
403permission_errorThe API key doesn't have permission
404not_found_errorThe requested model was not found
429rate_limit_errorRate limit exceeded
500server_errorServer error

Next Steps