Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content
Guides

Connect with the Anthropic SDK

In an SDK, update where you create your client: give it Mubit's base URL and your Mubit key. With curl, change the URL and the key in its header. Keep your model IDs and the rest of your code.

Base URL

The base URL is https://api.mubit.ai/anthropic. Leave /v1 off the end: the Anthropic SDK adds it.

Use the base URL your console's Connect page shows.

Key

Pass your Mubit key as the SDK's API key. The SDK sends it in the x-api-key header. Mubit also reads it from Authorization: Bearer.

The examples read the key from MUBIT_API_KEY. To create a key and set it, follow step 1 of the Quickstart.

ℹ️Note

Send your Mubit key only. If ANTHROPIC_AUTH_TOKEN holds another credential, the Anthropic SDKs can send it beside your key, and Mubit refuses the call with a 401. Unset it, or set it to your Mubit key.

Send a call

Install the SDK: pip install anthropic for Python, or npm install @anthropic-ai/sdk for TypeScript.

Python
import os
from anthropic import Anthropic
 
client = Anthropic(
    base_url="https://api.mubit.ai/anthropic",  # no /v1
    api_key=os.environ["MUBIT_API_KEY"],
)
 
instructions = (
    "Sort the support message into one category: "
    "billing, bug, account or other. Reply with the category only."
)
 
message = client.messages.create(
    model="claude-haiku-4-5",
    max_tokens=64,
    system=instructions,
    messages=[
        {"role": "user", "content": "I was charged twice for my October invoice."},
    ],
)
print(message.content[0].text)

The TypeScript examples use top-level await, so run them as ES modules: save the file as anthropic.mts and run npx tsx anthropic.mts, or add "type": "module" to your package.json.

Stream the answer

Use the SDK's stream helper, or set stream to true. Mubit streams the answer back to your app.

Python
import os
from anthropic import Anthropic
 
client = Anthropic(
    base_url="https://api.mubit.ai/anthropic",  # no /v1
    api_key=os.environ["MUBIT_API_KEY"],
)
 
with client.messages.stream(
    model="claude-haiku-4-5",
    max_tokens=256,
    system="Reply to the support message in two short sentences.",
    messages=[
        {"role": "user", "content": "I was charged twice for my October invoice."},
    ],
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)
print()

curl -N prints each event as it arrives.

Or set the SDK's environment variables

The Anthropic SDK reads its base URL and key from the environment when your code doesn't pass them. To point an app at Mubit without a code change, set these two variables where it runs:

export ANTHROPIC_BASE_URL=https://api.mubit.ai/anthropic
export ANTHROPIC_API_KEY="$MUBIT_API_KEY"
unset ANTHROPIC_AUTH_TOKEN

The SDKs can send ANTHROPIC_AUTH_TOKEN beside the key, so the last line unsets it. Another credential left there would make Mubit refuse the call.

See the call in Requests

  1. In the console, open Requests.
  2. Find your call at the top. The list is newest first.
  3. Check Model asked. It shows the model ID your app sent.
  4. Select the row. The call opens with its Request and its Reply.

A streamed call shows its whole reply.

What Mubit forwards and trains on

  • Forwarded: when Mubit sends a call on to Anthropic, it sends your request with your Anthropic key, or the starter credit's key, in place of your Mubit key. Headers such as anthropic-version and anthropic-beta go on as you sent them. Cookies, x-middleware-store and x-middleware-record don't. On the starter credit, some models, paths and options are refused: see Starter credit errors.
  • Trained on: adapters train only on kept examples: the recorded calls Mubit accepts for a task. A call recorded without its request and reply is never a kept example.

Frameworks and coding tools

Frameworks covers the Vercel AI SDK and LangChain, and Coding tools covers Claude Code.

If a call fails

The error names its code. Troubleshooting lists the codes and what to do. Each answer carries the call's ID in the x-middleware-request-id header: see Find a call's request ID.

Next