Anthropic
How to use GATE/0 with Anthropic
GATE/0 is fully compatible with the Anthropic REST API, making integration seamless. You can use both the OpenAI and Anthropic SDKs with GATE/0 to interact with Anthropic models. In this guide we cover how to use both. Let's start with the OpenAI SDK.
Using OpenAI SDK
Set up your Anthropic provider in GATE/0
Install OpenAI SDK
pip install openainpm install openaiConfigure the GATE/0 API key Set your GATE/0 API key as an environment variable:
export GATE0_API_KEY=your-gate0-api-keyStart using Anthropic SDK
import OpenAI from 'openai';
const openai = new OpenAI({
baseURL: "https://gateway.gate.io/v1", // GATE0 cloud proxy URL
apiKey: process.env.GATE0_API_KEY, // API key provided by GATE0
});
const chatCompletion = await openai.chat.completions.create({
model: "anthropic/claude-3-5-sonnet-latest", // Model name with provider prefix
messages: [{ role: 'user', content: "Hello, how are you?" }],
metadata: { // Custom labels
"gate0_label_project":"alpha",
"gate0_label_client":"frontend",
"gate0_label_env":"prod"
}
});
console.log(chatCompletion.choices);from openai import OpenAI
import os
client = OpenAI(
base_url="https://gateway.gate.io/v1", # GATE0 cloud proxy URL
api_key=os.environ.get("GATE0_API_KEY"), # API key provided by GATE0
)
completion = client.chat.completions.create(
model="anthropic/claude-3-5-sonnet-latest", # Model name with provider prefix
messages=[
{"role": "user", "content": "Hello, how are you?"}
],
extra_body={
"metadata": { # Custom labels
"gate0_label_project":"alpha",
"gate0_label_client":"frontend",
"gate0_label_env":"prod"
}
}
)
print(completion.choices[0].message)Explanation of the implementation
- An instance of
OpenAIis created with the base URL set tohttps://gateway.gate0.io/v1, using your GATE0 API key instead of the default OpenAI key. - A prefixed model name is used. Make sure the model name is prefixed with the provider slug (e.g., use
anthropic/claude-3-5-sonnet-latestinstead ofclaude-3-5-sonnet-latest). - Custom labels are included to allocate and track costs more effectively.
Using Anthropic SDK
Set up your Anthropic provider in GATE/0
Install Anthropic SDK
pip install anthropicnpm install @anthropic-ai/sdkimport 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", // Make sure not to use /v1 in the base 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", # Make sure not to use /v1 in the base 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
- An instance of
Anthropicis created with the base URL set tohttps://gateway.gate0.io, using your GATE0 API key instead of the default Anthropic key. - A prefixed model name is used. Make sure the model name is prefixed with the provider slug (e.g., use
anthropic/claude-sonnet-4-20250514instead ofclaude-sonnet-4-20250514). - Custom labels are included to allocate and track costs more effectively.
Base URL
Please note that the base URL should be set to https://gateway.gate0.io. It must not not end with /v1 even
though the messages endpoint is https://api.anthropic.com/v1/messages. In contract to the OpenAI API, Anthropic is using /v1 as a part of endpoint URL and not the base URL. GATE/0 gateway handles this for you. Just remember
to not include /v1 in the base URL.