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

# Anthropic SDK drop-in integration

> Route Anthropic SDK calls through the orq.ai AI Gateway. Access fallbacks, caching, load balancing, and cost tracking for all Claude models.

<CardGroup cols={2}>
  <Card title="AI Gateway" icon="arrow-right-arrow-left" href="#ai-gateway">
    Route Claude calls through the **AI Gateway** with a single base URL change. Zero vendor lock-in: always run on the best model at the lowest cost for the use case.
  </Card>

  <Card title="Claude Agent SDK" icon="robot" href="/docs/ai-studio/integrations/frameworks/claude-agent-sdk">
    Building programmable agents with multi-turn conversations, tool use, and MCP servers? Use the Claude Agent SDK instead.
  </Card>
</CardGroup>

## AI Gateway

### Overview

The Anthropic SDK (`@anthropic-ai/sdk` and `anthropic`) is the native client for the Claude Messages API. Connect it to **Orq.ai**'s **AI Gateway** with a single `base_url` change and no other modifications to existing code, unlocking 300+ models across 20+ providers, fallbacks, caching, and cost tracking.

<Info>
  For programmable agents with multi-turn conversations, tool use, and MCP servers, see the [Claude Agent SDK](/docs/ai-studio/integrations/frameworks/claude-agent-sdk) integration.
</Info>

### Key Benefits

Orq.ai's **AI Gateway** enhances the Anthropic SDK with:

<CardGroup cols={2}>
  <Card title="Complete Observability" icon="chart-line">
    Track every API call, token usage, and model interaction with detailed traces and analytics
  </Card>

  <Card title="Built-in Reliability" icon="shield-check">
    Automatic fallbacks, retries, and load balancing for production resilience
  </Card>

  <Card title="Cost Optimization" icon="chart-pie">
    Real-time cost tracking and spend management across all AI operations
  </Card>

  <Card title="Multi-Provider Access" icon="cubes">
    Access 300+ LLMs and 20+ providers through a single, unified integration
  </Card>
</CardGroup>

### Prerequisites

Before integrating the Anthropic SDK with **Orq.ai**, ensure the following are in place:

* An Orq.ai account and [API Key](/docs/ai-studio/organization/api-keys)
* Python 3.8+ or Node.js 18+ with TypeScript support
* Anthropic SDK installed

<Info>
  To set up an API key, see [API keys & Endpoints](/docs/ai-studio/organization/api-keys).
</Info>

### Installation

<CodeGroup>
  ```bash TypeScript theme={"theme":{"light":"github-light","dark":"github-dark"}}
  npm install @anthropic-ai/sdk
  ```

  ```bash Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  pip install anthropic
  ```
</CodeGroup>

### Configuration

Set the **Base URL** to the [AI Gateway](/docs/ai-studio/ai-gateway/add-models) and authenticate with an **Orq.ai** API key to route calls through the API without changing any other part of the code.

> **base\_url**: `https://api.orq.ai/v3/anthropic`

<CodeGroup>
  ```typescript TypeScript theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import Anthropic from '@anthropic-ai/sdk';

  const client = new Anthropic({
    apiKey: process.env.ORQ_API_KEY,
    baseURL: 'https://api.orq.ai/v3/anthropic',
  });
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import os
  import anthropic

  client = anthropic.Anthropic(
      api_key=os.environ["ORQ_API_KEY"],
      base_url="https://api.orq.ai/v3/anthropic",
  )
  ```
</CodeGroup>

### Text Generation

Basic text generation with the Anthropic SDK through Orq.ai:

<CodeGroup>
  ```typescript TypeScript theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import Anthropic from '@anthropic-ai/sdk';

  const client = new Anthropic({
    apiKey: process.env.ORQ_API_KEY,
    baseURL: 'https://api.orq.ai/v3/anthropic',
  });

  const message = await client.messages.create({
    model: 'anthropic/claude-sonnet-4-6',
    max_tokens: 1024,
    messages: [
      { role: 'user', content: 'Explain the orq.ai AI Gateway in one paragraph.' },
    ],
  });

  const block = message.content[0];
  if (block.type === 'text') {
    console.log(block.text);
  }
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import os
  import anthropic

  client = anthropic.Anthropic(
      api_key=os.environ["ORQ_API_KEY"],
      base_url="https://api.orq.ai/v3/anthropic",
  )

  message = client.messages.create(
      model="anthropic/claude-sonnet-4-6",
      max_tokens=1024,
      messages=[{"role": "user", "content": "Explain the orq.ai AI Gateway in one paragraph."}],
  )

  print(message.content[0].text)
  ```
</CodeGroup>

### Streaming

Stream responses for real-time output:

<CodeGroup>
  ```typescript TypeScript theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import Anthropic from '@anthropic-ai/sdk';

  const client = new Anthropic({
    apiKey: process.env.ORQ_API_KEY,
    baseURL: 'https://api.orq.ai/v3/anthropic',
  });

  const stream = client.messages.stream({
    model: 'anthropic/claude-sonnet-4-6',
    max_tokens: 1024,
    messages: [
      { role: 'user', content: 'Write a haiku about AI routing.' },
    ],
  });

  stream.on('text', (text) => {
    process.stdout.write(text);
  });

  await stream.finalMessage();
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import os
  import anthropic

  client = anthropic.Anthropic(
      api_key=os.environ["ORQ_API_KEY"],
      base_url="https://api.orq.ai/v3/anthropic",
  )

  with client.messages.stream(
      model="anthropic/claude-sonnet-4-6",
      max_tokens=1024,
      messages=[{"role": "user", "content": "Write a haiku about AI routing."}],
  ) as stream:
      for text in stream.text_stream:
          print(text, end="", flush=True)
  ```
</CodeGroup>

### Tool Use

Define tools and let the model decide when to call them. The **AI Gateway** forwards tool definitions and returns `tool_use` blocks unchanged:

<CodeGroup>
  ```typescript TypeScript theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import Anthropic from '@anthropic-ai/sdk';

  const client = new Anthropic({
    apiKey: process.env.ORQ_API_KEY,
    baseURL: 'https://api.orq.ai/v3/anthropic',
  });

  const message = await client.messages.create({
    model: 'anthropic/claude-sonnet-4-6',
    max_tokens: 1024,
    tools: [
      {
        name: 'get_weather',
        description: 'Get the current weather for a location',
        input_schema: {
          type: 'object',
          properties: {
            location: { type: 'string', description: 'City name, e.g. Amsterdam' },
          },
          required: ['location'],
        },
      },
    ],
    messages: [
      { role: 'user', content: 'What is the weather in Amsterdam?' },
    ],
  });

  for (const block of message.content) {
    if (block.type === 'tool_use') {
      console.log(`Tool: ${block.name}`, block.input);
    }
  }
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import os
  import anthropic

  client = anthropic.Anthropic(
      api_key=os.environ["ORQ_API_KEY"],
      base_url="https://api.orq.ai/v3/anthropic",
  )

  message = client.messages.create(
      model="anthropic/claude-sonnet-4-6",
      max_tokens=1024,
      tools=[
          {
              "name": "get_weather",
              "description": "Get the current weather for a location",
              "input_schema": {
                  "type": "object",
                  "properties": {
                      "location": {"type": "string", "description": "City name, e.g. Amsterdam"},
                  },
                  "required": ["location"],
              },
          }
      ],
      messages=[{"role": "user", "content": "What is the weather in Amsterdam?"}],
  )

  for block in message.content:
      if block.type == "tool_use":
          print(f"Tool: {block.name}", block.input)
  ```
</CodeGroup>

### Model Selection

The `anthropic/` prefix routes to Claude models. Switch to any supported model from 20+ providers by changing the `model` value:

<CodeGroup>
  ```typescript TypeScript theme={"theme":{"light":"github-light","dark":"github-dark"}}
  const message = await client.messages.create({
    model: 'openai/gpt-4o',
    max_tokens: 1024,
    messages: [{ role: 'user', content: 'Explain machine learning' }],
  });
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  message = client.messages.create(
      model="openai/gpt-4o",
      max_tokens=1024,
      messages=[{"role": "user", "content": "Explain machine learning"}],
  )
  ```
</CodeGroup>

<Info>
  Browse every available model in [Supported Models](/docs/ai-studio/ai-gateway/supported-models).
</Info>
