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

# Python

> Build agentic workflows with the Anthropic Agent SDK and send traces to Keywords AI.

<Note>This integration is only for **Agent tracing**. If you are looking for the Anthropic integration with the AI gateway, please see the [Anthropic integration](/integration/development-frameworks/llm_framework/anthropic).</Note>

<Check>[Give us a star](https://github.com/Keywords-AI/keywordsai) on GitHub!</Check>

The [Anthropic Agent SDK](https://github.com/anthropics/anthropic-sdk-python) enables you to build agentic workflows powered by Claude. Keywords AI provides an exporter that automatically captures and sends traces from the Anthropic Agent SDK to Keywords AI for monitoring, debugging, and optimization.

## Quickstart

Install the Anthropic Agent SDK and the Keywords AI exporter, then configure the exporter to send traces to Keywords AI.

### Prerequisites

```bash theme={"system"}
pip install respan-exporter-anthropic-agents
```

Set up your environment variables:

```bash .env theme={"system"}
RESPAN_API_KEY=YOUR_KEYWORDSAI_API_KEY
RESPAN_BASE_URL=https://api.keywordsai.co
```

| Variable          | Required | Description                                                                                                                                               |
| ----------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `RESPAN_API_KEY`  | Yes      | Your Keywords AI API key                                                                                                                                  |
| `RESPAN_BASE_URL` | No       | Base URL for Keywords AI. Defaults to `https://api.keywordsai.co`. The exporter automatically appends `/api/v1/traces/ingest` to build the full endpoint. |

<Note>If you are on the enterprise platform, please use your enterprise endpoint as the base URL.</Note>

### Hello World example

```python theme={"system"}
import asyncio
from claude_agent_sdk import ClaudeAgentOptions
from respan_exporter_anthropic_agents.respan_anthropic_agents_exporter import (
    RespanAnthropicAgentsExporter,
)

exporter = RespanAnthropicAgentsExporter()

async def main() -> None:
    options = exporter.with_options(
        options=ClaudeAgentOptions(
            allowed_tools=["Read", "Glob", "Grep"],
            permission_mode="acceptEdits",
        )
    )

    async for message in exporter.query(
        prompt="Analyze this repository and summarize architecture.",
        options=options,
    ):
        print(message)

asyncio.run(main())
```

## Configuration

All configuration can also be passed directly to the constructor, which takes priority over environment variables:

```python theme={"system"}
exporter = RespanAnthropicAgentsExporter(
    api_key="your_keywordsai_key",          # Overrides RESPAN_API_KEY
    base_url="https://api.keywordsai.co",   # Overrides RESPAN_BASE_URL
    endpoint="https://custom/ingest",       # Full endpoint URL (overrides base_url)
    timeout_seconds=15,
    max_retries=3,
    base_delay_seconds=1.0,
    max_delay_seconds=30.0,
)
```
