Learn how to use Anthropic SDKs with Electron Hub as your base URL
Use Electron Hub with the official Anthropic SDKs by simply changing the base URL. This allows you to access Claude models and 450+ other AI models through familiar Anthropic interfaces.
import json# Define toolstools = [ { "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=1000, tools=tools, messages=[ { "role": "user", "content": "What's the weather like in Paris?" } ])print(message.content)# Handle tool usefor content in message.content: if content.type == "tool_use": print(f"Tool: {content.name}") print(f"Input: {content.input}")
const message = await anthropic.messages.create({ model: 'claude-3-5-sonnet-20241022', max_tokens: 1000, system: `You are a helpful AI assistant that specializes in explaining complex technical concepts in simple terms. Always: 1. Use analogies and examples 2. Break down complex ideas into steps 3. Ask clarifying questions if needed 4. Provide practical applications`, messages: [ { role: 'user', content: 'Explain quantum computing' } ]});
const message = await anthropic.messages.create({ model: 'claude-3-5-sonnet-20241022', max_tokens: 1000, system: 'You are a JSON generator. Always respond with valid JSON.', messages: [ { role: 'user', content: 'Generate a JSON object with information about a fictional character including name, age, occupation, and three personality traits.' } ]});const characterData = JSON.parse(message.content[0].text);console.log(characterData);
// Use Haiku for simple tasksconst quickResponse = await anthropic.messages.create({ model: 'claude-3-haiku-20240307', max_tokens: 100, messages: [{ role: 'user', content: 'What time is it in UTC?' }]});// Use Opus for complex reasoningconst complexAnalysis = await anthropic.messages.create({ model: 'claude-3-opus-20240229', max_tokens: 2000, messages: [{ role: 'user', content: 'Analyze the economic implications of...' }]});