> ## Documentation Index
> Fetch the complete documentation index at: https://docs.corvex.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# Use the Anthropic SDK

> Configure the official Anthropic Python or TypeScript SDK to call Corvex Token Factory through the Messages API.

Keep the official Anthropic client and Messages API request format. Change the
client's base URL and API key, then choose a model from the Corvex Token Factory
catalog. Model IDs and feature support differ from Anthropic's hosted models.

## Prerequisites

* A Token Factory API key. See [Authentication](/getting-started/authentication).
* Python with the `anthropic` package, or Node.js with the `@anthropic-ai/sdk`
  package.
* A model ID from the [live catalog](/models/overview).

Set the key in your shell:

```bash theme={null}
export CORVEX_API_KEY="sk-corvex-YOUR_VIRTUAL_KEY"
```

## Configure the client

<CodeGroup>
  ```python python {6-7} theme={null}
  import os

  from anthropic import Anthropic

  client = Anthropic(
      api_key=os.environ["CORVEX_API_KEY"],
      base_url="https://api.tokenfactory.corvex.cloud",
  )

  message = client.messages.create(
      model="zai-org/GLM-5.3",
      max_tokens=1024,
      messages=[{"role": "user", "content": "Explain this function."}],
  )
  print(next(block.text for block in message.content if block.type == "text"))
  ```

  ```typescript TypeScript {4-5} theme={null}
  import Anthropic from "@anthropic-ai/sdk";

  const client = new Anthropic({
    apiKey: process.env.CORVEX_API_KEY,
    baseURL: "https://api.tokenfactory.corvex.cloud",
  });

  const message = await client.messages.create({
    model: "zai-org/GLM-5.3",
    max_tokens: 1024,
    messages: [{ role: "user", content: "Explain this function." }],
  });
  console.log(message.content.find((block) => block.type === "text")?.text);
  ```
</CodeGroup>

The highlighted constructor fields route the client to Token Factory. The base
URL has no `/v1` suffix; the SDK appends `/v1/messages` itself and sends the key
in the `x-api-key` header. `max_tokens` is required by the Messages API.

Both Token Factory models reason before answering, so `content` starts with a
`thinking` block followed by the `text` block. Select the block by `type` rather
than by position, as the examples do. Reasoning tokens count toward
`max_tokens`.

## Run the repository examples

```bash theme={null}
# Python
python -m pip install anthropic
python integrations/anthropic-drop-in/python.py

# Node.js
npm install @anthropic-ai/sdk
node integrations/anthropic-drop-in/node.mjs
```

A non-`2xx` response raises the SDK's API error type with the Anthropic-shaped
Token Factory error body. See
[Errors: Anthropic endpoints](/reference/errors#anthropic-endpoints-v1messages).

## Streaming and tool use

The endpoint accepts `stream: true` and returns the Anthropic Server-Sent Events
sequence (`message_start`, `content_block_delta`, ..., `message_stop`), so the
SDK's streaming helpers work as they do against Anthropic. Tool definitions and
`tool_use` / `tool_result` content blocks are accepted for both Token Factory
models.

## Count tokens

`POST /v1/messages/count_tokens` validates the key and request shape without
running inference:

```python theme={null}
count = client.messages.count_tokens(
    model="deepseek-ai/DeepSeek-V4-Flash-0731",
    messages=[{"role": "user", "content": "Hello"}],
)
print(count.input_tokens)
```

## Compatibility notes

* **Model IDs.** Use the Token Factory `namespace/model` ID exactly as
  `GET /v1/models` returns it. Anthropic model names are not served.
* **Prompt caching.** The endpoint accepts `cache_control` but Token Factory does
  not treat it as a request to cache content. See
  [Errors: Prompt caching](/reference/errors#prompt-caching-cache_control).
* **Input types.** Neither model accepts image input. Unsupported inputs return
  a structured error.

## Related documentation

* [Connect Claude Code](/integrations/claude-code) — the same Messages API from
  the Claude Code CLI.
* [Use the OpenAI SDK](/integrations/openai-drop-in) — the Chat Completions
  surface for OpenAI clients.
* [API reference](/api-reference/openapi) — supported Messages API request and
  response fields.
