Skip to main content

AI Gateway

Overview

The Anthropic SDK (@anthropic-ai/sdk and anthropic) is the native client for the Claude Messages API. Connecting it to Orq.ai’s AI Gateway with a single base_url change unlocks 300+ models across 20+ providers, fallbacks, caching, and cost tracking, with no other modifications to existing code.
For programmable agents with multi-turn conversations, tool use, and MCP servers, see the Claude Agent SDK integration.

Key Benefits

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

Complete Observability

Track every API call, token usage, and model interaction with detailed traces and analytics

Built-in Reliability

Automatic fallbacks, retries, and load balancing for production resilience

Cost Optimization

Real-time cost tracking and spend management across all AI operations

Multi-Provider Access

Access 300+ LLMs and 20+ providers through a single, unified integration

Prerequisites

Before integrating the Anthropic SDK with Orq.ai, ensure the following are in place:
  • An Orq.ai account and API Key
  • Python 3.8+ or Node.js 18+ with TypeScript support
  • Anthropic SDK installed
To set up an API key, see API keys & Endpoints.

Installation

npm install @anthropic-ai/sdk

Configuration

Set the Base URL to the AI Gateway 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
import Anthropic from '@anthropic-ai/sdk';

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

Text Generation

Basic text generation with the Anthropic SDK through Orq.ai:
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);
}

Streaming

Stream responses for real-time output:
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();

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:
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);
  }
}

Model Selection

The anthropic/ prefix routes to Claude models. Switch to any supported model from 20+ providers by changing the model value:
const message = await client.messages.create({
  model: 'openai/gpt-4o',
  max_tokens: 1024,
  messages: [{ role: 'user', content: 'Explain machine learning' }],
});
Browse every available model in Supported Models.