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
Bearer Token
Anthropic Style
curl https://www.llmadaptive.uk/api/v1/messages \
-H "Authorization: Bearer your-adaptive-key" \
-H "Content-Type: application/json"
Basic Request
JavaScript/Node.js
Python
cURL
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 identifier. Use ""
(empty string) for intelligent routing.
Array of message objects representing the conversation history.
Maximum number of tokens to generate in the response.
Message Object
The role of the message sender. Must be either "user"
or "assistant"
.
The content of the message. Can be a string or array of content blocks for multimodal inputs.
Optional Parameters
System prompt to guide the model’s behavior.
Sampling temperature between 0 and 1. Higher values make output more random.
Nucleus sampling parameter. Controls diversity of generated text.
Top-k sampling parameter. Limits vocabulary to top k tokens.
Array of strings where the model should stop generating.
Intelligent Routing Parameters
These additional parameters control Adaptive’s intelligent routing:
Configuration for intelligent model selection. Balance between cost and performance (0-1). 0 = cheapest, 1 = best performance.
Array of allowed providers/models for this request.
Fallback configuration for provider failures. Enable/disable fallback (default: true).
Fallback strategy: “sequential” or “race”.
Example with Intelligent Routing
Advanced Configuration
Advanced Configuration
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 );
{
"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
Unique identifier for the message.
Always “message” for this endpoint.
Always “assistant” for responses.
Array of content blocks containing the generated response.
The specific model that generated the response.
Reason the model stopped generating: “end_turn”, “max_tokens”, or “stop_sequence”.
Token usage information. Number of tokens in the input.
Number of tokens in the output.
Adaptive Extension : Which AI provider was selected for this request.
Adaptive Extension : Cache performance information.
Streaming
Streaming Example
Streaming Example
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:
Before (Direct Claude)
After (Adaptive)
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