Documentation

Anthropic

How to use GATE/0 with Anthropic

GATE/0 is fully compatible with the Anthropic REST API, making integration seamless. Simply point your existing Anthropic client to GATE/0’s endpoint — no code changes required. You can enrich requests with custom labels to enable detailed tracking, cost allocation, and forecasting.

Whether you're using anthropic.messages.create() or other endpoints, GATE/0 acts as a transparent proxy, preserving all functionality while adding powerful analytics and observability.

Set up your Anthropic provider in GATE/0

  1. Retrieve your Anthropic API key from Anthropic
  2. Add a new Anthropic provider in GATE/0 here
  3. Copy your GATE/0 API key from here

Install Anthropic SDK

pip install anthropic
npm install @anthropic-ai/sdk

Configure the GATE/0 API key Set your GATE/0 API key as an environment variable:

export GATE0_API_KEY=your-gate0-api-key

Start using Anthropic SDK

import Anthropic from '@anthropic-ai/sdk';

const anthropic = new Anthropic({
    apiKey: process.env.GATE0_API_KEY, // API key provided by GATE0
    baseURL: "https://gateway.gate.io/v1", // GATE0 cloud proxy URL
});

const msg = await anthropic.messages.create(
    {
        model: "anthropic/claude-sonnet-4-20250514", // Model name with provider prefix
        max_tokens: 1024,
        messages: [{ role: "user", content: "Hello, how are you?" }],
    },
    {
        headers: { 
            "x-gate0-label-project": "alpha-1", 
            "x-gate0-label-client": "frontend", 
            "x-gate0-label-env": "prod"
        }
    }
);
console.log(msg);
from anthropic import Anthropic
import os

client = Anthropic(
    base_url="https://gateway.gate.io/v1", # GATE0 cloud gateway URL
    api_key=os.environ.get("GATE0_API_KEY"), # API key provided by GATE0
)

message = client.messages.create(
    model="anthropic/claude-3-5-sonnet-latest", # Model name with provider prefix
    max_tokens=1024,
    messages=[
        {"role": "user", "content": "Hello, Claude"}
    ],
    extra_headers={ # Custom labels
        "x-gate0-label-project":"alpha", 
        "x-gate0-label-client":"frontend", 
        "x-gate0-label-env":"prod"
    }
)
print(message.content)

Explanation of the implementation

  1. An instance of Anthropic is created with the base URL set to https://gateway.gate0.io/v1, using your GATE0 API key instead of the default Anthropic key.
  2. A prefixed model name is used. Make sure the model name is prefixed with the provider slug (e.g., use anthropic/claude-sonnet-4-20250514 instead of claude-sonnet-4-20250514).
  3. Custom labels are included to allocate and track costs more effectively.