Use Edgee with the Anthropic SDK for building AI applications with Claude models.
The Anthropic SDK provides official Python and TypeScript clients for interacting with Claude models. Edgee’s OpenAI-compatible API works seamlessly with the Anthropic SDK, allowing you to leverage the SDK’s features while gaining access to Edgee’s unified gateway, cost tracking, automatic failover, and observability.
import osfrom anthropic import Anthropic# Initialize client with Edgee endpointclient = Anthropic( base_url="https://api.edgee.ai/v1", api_key=os.environ.get("EDGEE_API_KEY"),)# Send a messagemessage = client.messages.create( model="claude-sonnet-4.5", max_tokens=1024, messages=[ {"role": "user", "content": "What is the capital of France?"} ])print(message.content[0].text)# "The capital of France is Paris."
Copy
Ask AI
import Anthropic from '@anthropic-ai/sdk';// Initialize client with Edgee endpointconst client = new Anthropic({ baseURL: 'https://api.edgee.ai/v1', apiKey: process.env.EDGEE_API_KEY,});// Send a messageconst message = await client.messages.create({ model: 'claude-sonnet-4.5', max_tokens: 1024, messages: [ { role: 'user', content: 'What is the capital of France?' } ]});console.log(message.content[0].text);// "The capital of France is Paris."
from anthropic import Anthropicclient = Anthropic( base_url="https://api.edgee.ai/v1", api_key=os.environ.get("EDGEE_API_KEY"),)# Stream messageswith client.messages.stream( model="claude-sonnet-4.5", max_tokens=1024, messages=[ {"role": "user", "content": "Write a short poem about coding"} ]) as stream: for text in stream.text_stream: print(text, end="", flush=True)
Copy
Ask AI
import Anthropic from '@anthropic-ai/sdk';const client = new Anthropic({ baseURL: 'https://api.edgee.ai/v1', apiKey: process.env.EDGEE_API_KEY,});// Stream messagesconst stream = await client.messages.create({ model: 'claude-sonnet-4.5', max_tokens: 1024, messages: [ { role: 'user', content: 'Write a short poem about coding' } ], stream: true,});for await (const event of stream) { if (event.type === 'content_block_delta' && event.delta.type === 'text_delta') { process.stdout.write(event.delta.text); }}
from anthropic import Anthropicclient = Anthropic( base_url="https://api.edgee.ai/v1", api_key=os.environ.get("EDGEE_API_KEY"),)# Define a tooltools = [ { "name": "get_weather", "description": "Get the current weather in a given location", "input_schema": { "type": "object", "properties": { "location": { "type": "string", "description": "The city and state, e.g. San Francisco, CA" } }, "required": ["location"] } }]# Send message with toolsmessage = client.messages.create( model="claude-sonnet-4.5", max_tokens=1024, tools=tools, messages=[ {"role": "user", "content": "What's the weather like in Paris?"} ])print(message.content)
Copy
Ask AI
import Anthropic from '@anthropic-ai/sdk';const client = new Anthropic({ baseURL: 'https://api.edgee.ai/v1', apiKey: process.env.EDGEE_API_KEY,});// Define a toolconst tools = [ { name: 'get_weather', description: 'Get the current weather in a given location', input_schema: { type: 'object', properties: { location: { type: 'string', description: 'The city and state, e.g. San Francisco, CA' } }, required: ['location'] } }];// Send message with toolsconst message = await client.messages.create({ model: 'claude-sonnet-4.5', max_tokens: 1024, tools: tools, messages: [ { role: 'user', content: "What's the weather like in Paris?" } ]});console.log(message.content);
Add custom tags to track and filter requests in Edgee’s dashboard:
Python
TypeScript
Copy
Ask AI
from anthropic import Anthropicclient = Anthropic( base_url="https://api.edgee.ai/v1", api_key=os.environ.get("EDGEE_API_KEY"), default_headers={ "x-edgee-tags": "production,anthropic-sdk,user-123" })# All requests from this client will include these tagsmessage = client.messages.create( model="claude-sonnet-4.5", max_tokens=1024, messages=[{"role": "user", "content": "Hello!"}])
Copy
Ask AI
import Anthropic from '@anthropic-ai/sdk';const client = new Anthropic({ baseURL: 'https://api.edgee.ai/v1', apiKey: process.env.EDGEE_API_KEY, defaultHeaders: { 'x-edgee-tags': 'production,anthropic-sdk,user-123' }});// All requests from this client will include these tagsconst message = await client.messages.create({ model: 'claude-sonnet-4.5', max_tokens: 1024, messages: [{ role: 'user', content: 'Hello!' }]});
Tags are comma-separated strings that help you categorize and filter requests in Edgee’s analytics dashboard.