POST
/
api
/
v1
/
chat
/
completions
Chat Completions
curl --request POST \
  --url https://llmadaptive.uk/api/v1/chat/completions \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "<string>",
  "messages": [
    {
      "role": "<string>",
      "content": {},
      "name": "<string>"
    }
  ],
  "temperature": 123,
  "max_tokens": 123,
  "stream": true,
  "top_p": 123,
  "frequency_penalty": 123,
  "presence_penalty": 123,
  "tools": [
    {}
  ],
  "provider_constraint": [
    {}
  ],
  "cost_bias": 123
}'
{
  "id": "<string>",
  "object": "<string>",
  "created": 123,
  "model": "<string>",
  "provider": "<string>",
  "choices": [
    {
      "index": 123,
      "message": {
        "role": "<string>",
        "content": "<string>",
        "tool_calls": [
          {}
        ]
      },
      "finish_reason": "<string>"
    }
  ],
  "usage": {
    "prompt_tokens": 123,
    "completion_tokens": 123,
    "total_tokens": 123
  },
  "error": {
    "message": "<string>",
    "type": "<string>",
    "code": "<string>"
  }
}

Overview

The chat completions endpoint is fully compatible with OpenAI’s API while adding intelligent routing across multiple AI providers. Simply use an empty string for the model parameter to enable automatic provider selection.

Request

model
string
required
Model to use for completion. Use "" (empty string) for intelligent routing.
messages
array
required
Array of message objects representing the conversation.
temperature
number
Sampling temperature between 0 and 2. Higher values make output more random. Default: 1
max_tokens
integer
Maximum number of tokens to generate. Default varies by model.
stream
boolean
Whether to stream the response. Default: false
top_p
number
Nucleus sampling parameter. Default: 1
frequency_penalty
number
Penalty for token frequency. Range: -2.0 to 2.0. Default: 0
presence_penalty
number
Penalty for token presence. Range: -2.0 to 2.0. Default: 0
tools
array
Array of tool definitions for function calling.

Adaptive-Specific Parameters

provider_constraint
array
Array of provider names to limit selection. Available: ["openai", "anthropic", "gemini", "groq", "deepseek", "grok"]
cost_bias
number
Bias towards cost optimization. Range: 0-1 where 0 = cheapest, 1 = best performance. Default: 0.5

Response

id
string
Unique identifier for the completion
object
string
Object type, always chat.completion
created
integer
Unix timestamp of creation
model
string
Model used for the completion
provider
string
Adaptive addition: Which provider was selected (e.g., “openai”, “anthropic”)
choices
array
Array of completion choices
usage
object
Token usage statistics

Examples

Basic Chat

const completion = await openai.chat.completions.create({
  model: '',
  messages: [
    { role: 'user', content: 'Explain quantum computing simply' }
  ],
});

console.log(completion.choices[0].message.content);

With Provider Constraints

const completion = await openai.chat.completions.create({
  model: '',
  messages: [
    { role: 'user', content: 'Write a Python function to sort a list' }
  ],
  provider_constraint: ['anthropic', 'deepseek'], // Only use these providers
  cost_bias: 0.2 // Prefer cost savings
});

Streaming Response

const stream = await openai.chat.completions.create({
  model: '',
  messages: [
    { role: 'user', content: 'Tell me a story about space exploration' }
  ],
  stream: true
});

for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content || '');
}

Function Calling

const completion = await openai.chat.completions.create({
  model: '',
  messages: [
    { role: 'user', content: 'What\'s the weather like in San Francisco?' }
  ],
  tools: [
    {
      type: 'function',
      function: {
        name: 'get_weather',
        description: 'Get current weather for a location',
        parameters: {
          type: 'object',
          properties: {
            location: {
              type: 'string',
              description: 'City and state, e.g. San Francisco, CA'
            }
          },
          required: ['location']
        }
      }
    }
  ]
});

Vision (Multimodal)

const completion = await openai.chat.completions.create({
  model: '',
  messages: [
    {
      role: 'user',
      content: [
        { type: 'text', text: 'What\'s in this image?' },
        {
          type: 'image_url',
          image_url: {
            url: 'https://example.com/image.jpg'
          }
        }
      ]
    }
  ]
});

Error Responses

error
object
Error information

Common Errors

Status CodeError TypeDescription
400invalid_request_errorInvalid request format or parameters
401authentication_errorInvalid or missing API key
403permission_errorAPI key doesn’t have required permissions
429rate_limit_errorRate limit exceeded
500server_errorInternal server error

Rate Limits

PlanRequests per MinuteTokens per Minute
Free10010,000
Pro1,000100,000
EnterpriseCustomCustom
Rate limits are applied per API key and reset every minute.

Best Practices

Model Selection

Use empty string "" for model to enable intelligent routing and cost savings

Cost Control

Use cost_bias parameter to balance cost vs performance for your use case

Provider Limits

Use provider_constraint to limit which providers can be selected

Error Handling

Always implement proper error handling for network and API failures