On this page

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#

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#

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_use and tool_result blocks, and tool_choice.
  • Streams, with the stream helpers of the SDKs.
  • temperature, top_p and top_k.
  • The cost of each request: the header X-Ember-Cost-Micro-Usd, and ember.cost_micro_usd in the message (or in message_delta for a stream).

What does not work#

  • Dedicated deployments. Use /v1/chat/completions for 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_control and ignores it.

Errors have the Anthropic format, so the error classes of the SDKs work. Nuemetrix does not keep prompts or responses.