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

# Anthropic SDK setup

> Use Messages and token counting with the Anthropic Python SDK.

## Before you start

Complete organization setup, make sure your account has inference credit, and create a key on the [API Keys page](https://platform.pearlresearch.ai/api-keys). Most coding agents need a tool-capable chat model; Aider's basic edit workflow does not require native tool calling. Image input and reasoning support depend on the model. These terminal examples use Bash or Zsh on macOS, Linux, or Windows through WSL.

You need Python 3.10 or later and pip to run the SDK examples below. Install the package in the Python environment you use for your application.

## Get your connection settings

Open [Integrations](https://platform.pearlresearch.ai/integrations), select a model, then choose Anthropic SDK. The screen uses your organization's region. The examples below use the public global endpoint; replace it with your regional endpoint and replace `YOUR_MODEL_ID` with the full model ID shown there. Choose one of the models listed for this integration.

Set your Pearl API key in the terminal where you run Anthropic SDK:

```bash theme={null}
export PEARL_API_KEY="YOUR_PEARL_API_KEY"
```

## Configure Anthropic SDK

Save the Python example as `pearl_example.py` in this directory.

```bash Install theme={null}
python3 -m pip install anthropic
```

```python Messages and token counting theme={null}
import os
from anthropic import Anthropic

client = Anthropic(
    base_url="https://inference.pearlresearch.ai",
    api_key=os.environ["PEARL_API_KEY"],
    default_headers={"anthropic-version": "2023-06-01"},
)
messages = [{"role": "user", "content": "Hello!"}]
count = client.messages.count_tokens(model="YOUR_MODEL_ID", messages=messages)
print(count.input_tokens)
response = client.messages.create(
    model="YOUR_MODEL_ID",
    max_tokens=8192,  # covers the thinking and the answer
    messages=messages,
    # Levels the model does not serve round up to the next one it does (GET /models lists them).
    extra_body={"output_config": {"effort": "high"}},
    # thinking={"type": "disabled"},  # turns thinking off (models marked mandatory return 400)
)
for block in response.content:
    if block.type == "thinking":
        print("Thinking:", block.thinking)
    elif block.type == "text":
        print(block.text)
```

In a conversation, append the assistant's complete `response.content` to your messages before the next user turn. Keep thinking and tool-use blocks intact; send each tool result with its corresponding tool-use ID. See the [Messages reference](/docs/reference/messages.md) for streaming events and token counting.

Run the saved example in the same terminal where you set your API key:

```bash theme={null}
python3 pearl_example.py
```

A successful run prints the input token count, then the model reply.

## Set reasoning effort

The examples set the effort with `extra_body={"output_config": {"effort": "high"}}`, and `thinking={"type": "disabled"}` turns thinking off. Thinking budgets (`budget_tokens`) are not supported.

Accepted levels are `minimal`, `low`, `medium`, `high`, `xhigh`, and `max`. The set a model actually serves is `supported_efforts` in its `reasoning` block on [GET /models](/docs/reference/models.md); any other level rounds up to the next served one, or to the highest past the top ([how levels map](/docs/reasoning.md#effort-mapping)). Omit the field for the model's default, which is `max` on GLM-5.3, so set it explicitly for agents and pipelines. GLM-5.3 and GLM-5.3-Flash always reason and return `400` on the off switch. The output token limit covers the reasoning and the answer.

## Stream a reply

Save this example as `pearl_stream.py` to print text as it arrives:

```python theme={null}
import os
from anthropic import Anthropic

client = Anthropic(
    base_url="https://inference.pearlresearch.ai",
    api_key=os.environ["PEARL_API_KEY"],
    default_headers={"anthropic-version": "2023-06-01"},
)
with client.messages.stream(
    model="YOUR_MODEL_ID", max_tokens=8192,
    messages=[{"role": "user", "content": "Hello!"}],
    # Levels the model does not serve round up to the next one it does (GET /models lists them).
    extra_body={"output_config": {"effort": "high"}},
    # thinking={"type": "disabled"},  # turns thinking off (models marked mandatory return 400)
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)
    print("\nUsage:", stream.get_final_message().usage)
```

```bash theme={null}
python3 pearl_stream.py
```

## Start using Anthropic SDK

Replace the example prompt with your own request. You can review token usage and costs on the [Analytics page](https://platform.pearlresearch.ai/usage).

## Troubleshooting

* `401`: check the key and allow time for a newly created key to reach the inference gateway.
* `404`: copy the endpoint and exact model ID from Integrations. OpenAI base URLs end in `/v1`; the Anthropic SDK and Claude Code use the URL without that suffix.
* `402`: check your organization's credit and billing status.
* `429` or Anthropic `529`: respect retry instructions and reduce concurrency.
* For truncated output, check the output limit and reasoning budget. Increase limits only within the model's maximum output length.
* If pip is missing or reports `externally-managed-environment`, follow the [Python package installation guide](https://packaging.python.org/en/latest/tutorials/installing-packages/) for your Python installation, then use that same interpreter to install the SDK and run the example.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.