POST
/
api
/
v1
/
messages
Messages
curl --request POST \
  --url https://www.llmadaptive.uk/api/v1/messages \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "<string>",
  "messages": [
    {}
  ],
  "max_tokens": 123,
  "role": "<string>",
  "content": {},
  "system": "<string>",
  "temperature": 123,
  "top_p": 123,
  "top_k": 123,
  "stop_sequences": [
    {}
  ],
  "model_router": {
    "cost_bias": 123,
    "models": [
      {}
    ]
  },
  "fallback": {
    "enabled": true,
    "mode": "<string>"
  }
}'
{
  "id": "<string>",
  "type": "<string>",
  "role": "<string>",
  "content": [
    {}
  ],
  "model": "<string>",
  "stop_reason": "<string>",
  "usage": {
    "input_tokens": 123,
    "output_tokens": 123
  },
  "provider": "<string>",
  "cache_tier": "<string>"
}

Overview

The Messages endpoint provides an Anthropic Claude-compatible API with intelligent routing across multiple providers. Use this endpoint when you prefer Anthropic’s message format or are migrating from Claude.

Endpoint

POST https://www.llmadaptive.uk/api/v1/messages

Authentication

curl https://www.llmadaptive.uk/api/v1/messages \
  -H "Authorization: Bearer your-adaptive-key" \
  -H "Content-Type: application/json"

Basic Request

import Anthropic from '@anthropic-ai/sdk';

const anthropic = new Anthropic({
  apiKey: 'your-adaptive-key',
  baseURL: 'https://www.llmadaptive.uk/api/v1'
});

const message = await anthropic.messages.create({
  model: '', // Empty for intelligent routing
  max_tokens: 1000,
  messages: [
    { role: 'user', content: 'Hello! How are you?' }
  ]
});

console.log(message.content[0].text);

Request Parameters

Required Parameters

model
string
required
Model identifier. Use "" (empty string) for intelligent routing.
messages
array
required
Array of message objects representing the conversation history.
max_tokens
integer
required
Maximum number of tokens to generate in the response.

Message Object

role
string
required
The role of the message sender. Must be either "user" or "assistant".
content
string or array
required
The content of the message. Can be a string or array of content blocks for multimodal inputs.

Optional Parameters

system
string
System prompt to guide the model’s behavior.
temperature
number
Sampling temperature between 0 and 1. Higher values make output more random.
top_p
number
Nucleus sampling parameter. Controls diversity of generated text.
top_k
integer
Top-k sampling parameter. Limits vocabulary to top k tokens.
stop_sequences
array
Array of strings where the model should stop generating.

Intelligent Routing Parameters

These additional parameters control Adaptive’s intelligent routing:
model_router
object
Configuration for intelligent model selection.
fallback
object
Fallback configuration for provider failures.

Example with Intelligent Routing

import Anthropic from '@anthropic-ai/sdk';

const anthropic = new Anthropic({
  apiKey: 'your-adaptive-key',
  baseURL: 'https://www.llmadaptive.uk/api/v1'
});

const message = await anthropic.messages.create({
  model: '',
  max_tokens: 1000,
  system: 'You are a helpful AI assistant focused on clear, concise answers.',
  messages: [
    { 
      role: 'user', 
      content: 'Explain machine learning in simple terms' 
    }
  ],
  temperature: 0.7,
  
  // Adaptive intelligent routing
  model_router: {
    cost_bias: 0.3, // Favor cost savings
    models: [
      { provider: 'anthropic' },
      { provider: 'openai' },
      { provider: 'deepseek' }
    ]
  },
  
  // Fallback configuration
  fallback: {
    enabled: true,
    mode: 'race'
  }
});

console.log(message.content[0].text);

Response Format

{
  "id": "msg_abc123",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "text",
      "text": "Machine learning is a method of teaching computers to learn patterns from data..."
    }
  ],
  "model": "claude-3-haiku",
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 25,
    "output_tokens": 150
  },
  "provider": "anthropic",      // Which provider was used
  "cache_tier": "none"          // Cache performance info
}

Response Fields

id
string
Unique identifier for the message.
type
string
Always “message” for this endpoint.
role
string
Always “assistant” for responses.
content
array
Array of content blocks containing the generated response.
model
string
The specific model that generated the response.
stop_reason
string
Reason the model stopped generating: “end_turn”, “max_tokens”, or “stop_sequence”.
usage
object
Token usage information.
provider
string
Adaptive Extension: Which AI provider was selected for this request.
cache_tier
string
Adaptive Extension: Cache performance information.

Streaming

import Anthropic from '@anthropic-ai/sdk';

const anthropic = new Anthropic({
  apiKey: 'your-adaptive-key',
  baseURL: 'https://www.llmadaptive.uk/api/v1'
});

const stream = await anthropic.messages.create({
  model: '',
  max_tokens: 1000,
  messages: [
    { role: 'user', content: 'Tell me a story about AI' }
  ],
  stream: true
});

for await (const messageStreamEvent of stream) {
  if (messageStreamEvent.type === 'content_block_delta') {
    process.stdout.write(messageStreamEvent.delta.text);
  }
}

Migration from Claude

Simply change the base URL - everything else works the same:
import anthropic

client = anthropic.Anthropic(api_key="sk-ant-your-key")

message = client.messages.create(
    model="claude-3-sonnet-20240229",
    max_tokens=1000,
    messages=[{"role": "user", "content": "Hello"}]
)

Error Handling

The endpoint returns standard Anthropic-compatible error responses:
{
  "type": "error",
  "error": {
    "type": "invalid_request_error",
    "message": "max_tokens is required"
  }
}

Next Steps