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 up to 50% cost reduction through token compression, unified gateway, automatic failover, and full observability.
from anthropic import Anthropicclient = Anthropic( base_url="https://api.edgee.ai", 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', 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); }}
Edgee extends the Anthropic API response with a compression field containing compression metrics (input_tokens, saved_tokens, rate). All standard Anthropic fields remain unchanged.
from anthropic import Anthropicclient = Anthropic( base_url="https://api.edgee.ai", 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', 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", 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', 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.