from anthropic import Anthropicclient = Anthropic( base_url="https://api.llmgateway.io/v1", api_key="your-llmgateway-api-key")with client.messages.stream( model="claude-3-5-sonnet-20241022", max_tokens=1024, messages=[ {"role": "user", "content": "Write a short story"} ]) as stream: for text in stream.text_stream: print(text, end="", flush=True)
import Anthropic from '@anthropic-ai/sdk';const client = new Anthropic({ baseURL: 'https://api.llmgateway.io/v1', apiKey: 'your-llmgateway-api-key'});const stream = await client.messages.stream({ model: 'claude-3-5-sonnet-20241022', max_tokens: 1024, messages: [ { role: 'user', content: 'Write a short story' } ]});for await (const chunk of stream) { if (chunk.type === 'content_block_delta' && chunk.delta.type === 'text_delta') { process.stdout.write(chunk.delta.text); }}
from anthropic import Anthropicclient = Anthropic( base_url="https://api.llmgateway.io/v1", api_key="your-llmgateway-api-key")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"] } }]message = client.messages.create( model="claude-3-5-sonnet-20241022", max_tokens=1024, tools=tools, messages=[ {"role": "user", "content": "What's the weather in San Francisco?"} ])print(message.content)
import Anthropic from '@anthropic-ai/sdk';const client = new Anthropic({ baseURL: 'https://api.llmgateway.io/v1', apiKey: 'your-llmgateway-api-key'});const 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'] } }];const message = await client.messages.create({ model: 'claude-3-5-sonnet-20241022', max_tokens: 1024, tools, messages: [ { role: 'user', content: 'What\'s the weather in San Francisco?' } ]});console.log(message.content);
When using the native Anthropic format, use Anthropic’s model names:
# Claude 3.7 Sonnet (latest)model="claude-3-7-sonnet-20250219"# Claude 3.5 Sonnetmodel="claude-3-5-sonnet-20241022"# Claude 3 Opusmodel="claude-3-opus-20240229"# Claude 3.5 Haikumodel="claude-3-5-haiku-20241022"
With OpenAI-compatible format, you can use automatic routing:
# Auto-route to best Anthropic modelmodel="anthropic/claude-3-5-sonnet-20241022"# Or use LLM Gateway's unified namingmodel="gpt-5" # May route to Claude depending on availability