Anthropic SDKs
Use this page only when an existing application specifically requires Anthropic Messages. Otherwise, prefer the OpenAI SDK.
The Anthropic SDK base URL is the service origin, without a trailing /v1:
https://omrouter.comThe SDK appends /v1/messages itself.
Python
Section titled “Python”python -m pip install anthropicimport osfrom anthropic import Anthropic
client = Anthropic( api_key=os.environ["OMROUTER_API_KEY"], base_url="https://omrouter.com",)
message = client.messages.create( model=os.environ["OMROUTER_MODEL_ID"], max_tokens=256, messages=[ {"role": "user", "content": "Reply with one short sentence."} ],)
print(message.content[0].text)JavaScript
Section titled “JavaScript”npm install @anthropic-ai/sdkimport Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic({ apiKey: process.env.OMROUTER_API_KEY, baseURL: 'https://omrouter.com',});
const message = await client.messages.create({ model: process.env.OMROUTER_MODEL_ID, max_tokens: 256, messages: [ { role: 'user', content: 'Reply with one short sentence.' }, ],});
console.log(message.content[0]?.text);Direct HTTP request
Section titled “Direct HTTP request”curl --silent --show-error \ 'https://omrouter.com/v1/messages' \ --header "x-api-key: $OMROUTER_API_KEY" \ --header 'anthropic-version: 2023-06-01' \ --header 'content-type: application/json' \ --data "{ \"model\": \"$OMROUTER_MODEL_ID\", \"max_tokens\": 256, \"messages\": [ {\"role\": \"user\", \"content\": \"Reply with one short sentence.\"} ] }"Optional features
Section titled “Optional features”Tools, thinking, prompt caching, and image input depend on the selected model. Test the simple message above first, then add these features one at a time.
See Anthropic Messages for all fields.