Anthropic Messages API
Nuemetrix shared models also accept requests in the Anthropic Messages format, at POST /v1/messages. You can use the Anthropic SDKs without changes to your code: set the base URL to Nuemetrix and use an Nuemetrix API key.
Python#
import anthropic
client = anthropic.Anthropic(base_url="https://api.ember.ai", api_key="emb_live_...")
message = client.messages.create(
model="<shared model ID>",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello"}],
)
print(message.content[0].text)
TypeScript#
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({ baseURL: "https://api.ember.ai", apiKey: "emb_live_..." });
const message = await client.messages.create({
model: "<shared model ID>",
max_tokens: 1024,
messages: [{ role: "user", content: "Hello" }],
});
Use the API host of your region (see Data residency).
What works#
- Text, base64 images (PNG, JPEG, WebP), a system prompt and stop sequences.
- Tools: tool definitions,
tool_useandtool_resultblocks, andtool_choice. - Streams, with the stream helpers of the SDKs.
temperature,top_pandtop_k.- The cost of each request: the header
X-Ember-Cost-Micro-Usd, andember.cost_micro_usdin the message (or inmessage_deltafor a stream).
What does not work#
- Dedicated deployments. Use
/v1/chat/completionsfor them. - Images from a URL, documents, and the Anthropic server tools.
- Extended thinking and the other fields that are not in the list above. A request with them gets
400 invalid_request_error. - Prompt caching. Nuemetrix accepts
cache_controland ignores it.
Errors have the Anthropic format, so the error classes of the SDKs work. Nuemetrix does not keep prompts or responses.