diff --git a/docs.json b/docs.json index bee98ad..006bd76 100644 --- a/docs.json +++ b/docs.json @@ -85,8 +85,11 @@ { "group": "Integrations", "pages": [ - "integrations/langchain", - "integrations/opencode" + "integrations/claude-code", + "integrations/anthropic-sdk", + "integrations/openai-sdk", + "integrations/opencode", + "integrations/langchain" ] } ] @@ -101,7 +104,7 @@ "sdk/index", { "group": "TypeScript", - "icon": "https://d3gk2c5xim1je2.cloudfront.net/devicon/typescript.svg", + "icon": "/images/icons/typescript.svg", "pages": [ "sdk/typescript/index", "sdk/typescript/configuration", @@ -142,8 +145,7 @@ "sdk/go/stream", "sdk/go/tools" ] - }, - "sdk/openai/index" + } ] } ] diff --git a/images/icons/anthropic.svg b/images/icons/anthropic.svg new file mode 100644 index 0000000..0ada83b --- /dev/null +++ b/images/icons/anthropic.svg @@ -0,0 +1,10 @@ + + + + + diff --git a/images/icons/claude.svg b/images/icons/claude.svg new file mode 100644 index 0000000..c6b6efb --- /dev/null +++ b/images/icons/claude.svg @@ -0,0 +1,9 @@ + + + + diff --git a/integrations/anthropic-sdk.mdx b/integrations/anthropic-sdk.mdx new file mode 100644 index 0000000..bc2e879 --- /dev/null +++ b/integrations/anthropic-sdk.mdx @@ -0,0 +1,566 @@ +--- +title: Anthropic SDK +description: Use Edgee with the Anthropic SDK for building AI applications with Claude models. +icon: /images/icons/anthropic.svg +--- + +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. + +## Installation + + + + ```bash + pip install anthropic + ``` + + + ```bash + npm install @anthropic-ai/sdk + ``` + + + +## Basic Usage + + + + ```python + import os + from anthropic import Anthropic + + # Initialize client with Edgee endpoint + client = Anthropic( + base_url="https://api.edgee.ai/v1", + api_key=os.environ.get("EDGEE_API_KEY"), + ) + + # Send a message + message = 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." + ``` + + + + ```typescript + import Anthropic from '@anthropic-ai/sdk'; + + // Initialize client with Edgee endpoint + const client = new Anthropic({ + baseURL: 'https://api.edgee.ai/v1', + apiKey: process.env.EDGEE_API_KEY, + }); + + // Send a message + const 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." + ``` + + + +## Streaming Responses + +Stream responses for real-time token delivery: + + + + ```python + from anthropic import Anthropic + + client = Anthropic( + base_url="https://api.edgee.ai/v1", + api_key=os.environ.get("EDGEE_API_KEY"), + ) + + # Stream messages + with 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) + ``` + + + + ```typescript + import Anthropic from '@anthropic-ai/sdk'; + + const client = new Anthropic({ + baseURL: 'https://api.edgee.ai/v1', + apiKey: process.env.EDGEE_API_KEY, + }); + + // Stream messages + const 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); + } + } + ``` + + + +## Multi-Provider Access + +With Edgee, you can access models from multiple providers using the same Anthropic SDK client: + + + + ```python + from anthropic import Anthropic + + client = Anthropic( + base_url="https://api.edgee.ai/v1", + api_key=os.environ.get("EDGEE_API_KEY"), + ) + + # Use Claude + claude_response = client.messages.create( + model="claude-sonnet-4.5", + max_tokens=1024, + messages=[{"role": "user", "content": "Hello!"}] + ) + + # Use GPT-4 through the same client + gpt_response = client.messages.create( + model="gpt-4o", + max_tokens=1024, + messages=[{"role": "user", "content": "Hello!"}] + ) + + # Use Mistral + mistral_response = client.messages.create( + model="mistral-large", + max_tokens=1024, + messages=[{"role": "user", "content": "Hello!"}] + ) + ``` + + + + ```typescript + import Anthropic from '@anthropic-ai/sdk'; + + const client = new Anthropic({ + baseURL: 'https://api.edgee.ai/v1', + apiKey: process.env.EDGEE_API_KEY, + }); + + // Use Claude + const claudeResponse = await client.messages.create({ + model: 'claude-sonnet-4.5', + max_tokens: 1024, + messages: [{ role: 'user', content: 'Hello!' }] + }); + + // Use GPT-4 through the same client + const gptResponse = await client.messages.create({ + model: 'gpt-4o', + max_tokens: 1024, + messages: [{ role: 'user', content: 'Hello!' }] + }); + + // Use Mistral + const mistralResponse = await client.messages.create({ + model: 'mistral-large', + max_tokens: 1024, + messages: [{ role: 'user', content: 'Hello!' }] + }); + ``` + + + +## Function Calling (Tools) + +Use Claude's tool calling with Edgee: + + + + ```python + from anthropic import Anthropic + + client = Anthropic( + base_url="https://api.edgee.ai/v1", + api_key=os.environ.get("EDGEE_API_KEY"), + ) + + # Define a tool + 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 tools + message = 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) + ``` + + + + ```typescript + import Anthropic from '@anthropic-ai/sdk'; + + const client = new Anthropic({ + baseURL: 'https://api.edgee.ai/v1', + apiKey: process.env.EDGEE_API_KEY, + }); + + // Define a tool + 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'] + } + } + ]; + + // Send message with tools + const 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); + ``` + + + +## Tags for Observability + +Add custom tags to track and filter requests in Edgee's dashboard: + + + + ```python + from anthropic import Anthropic + + client = 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 tags + message = client.messages.create( + model="claude-sonnet-4.5", + max_tokens=1024, + messages=[{"role": "user", "content": "Hello!"}] + ) + ``` + + + + ```typescript + 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 tags + const 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. + + +## Error Handling and Retries + +The Anthropic SDK includes built-in retry logic, which works seamlessly with Edgee's automatic failover: + + + + ```python + from anthropic import Anthropic, APIError + + client = Anthropic( + base_url="https://api.edgee.ai/v1", + api_key=os.environ.get("EDGEE_API_KEY"), + max_retries=3, # SDK will retry up to 3 times + ) + + try: + message = client.messages.create( + model="claude-sonnet-4.5", + max_tokens=1024, + messages=[{"role": "user", "content": "Hello!"}] + ) + print(message.content[0].text) + except APIError as e: + print(f"API Error: {e}") + ``` + + + + ```typescript + import Anthropic from '@anthropic-ai/sdk'; + + const client = new Anthropic({ + baseURL: 'https://api.edgee.ai/v1', + apiKey: process.env.EDGEE_API_KEY, + maxRetries: 3, // SDK will retry up to 3 times + }); + + try { + const message = await client.messages.create({ + model: 'claude-sonnet-4.5', + max_tokens: 1024, + messages: [{ role: 'user', content: 'Hello!' }] + }); + console.log(message.content[0].text); + } catch (error) { + console.error('API Error:', error); + } + ``` + + + +## Authentication + +Edgee uses standard Bearer token authentication. Set your API key as an environment variable: + +```bash +export EDGEE_API_KEY="sk-edgee-..." +``` + +Or in your `.env` file: + +```bash +EDGEE_API_KEY=sk-edgee-... +``` + +The SDK automatically formats the authentication header as: +``` +Authorization: Bearer {api_key} +``` + +## Benefits of Using Anthropic SDK with Edgee + + + + Use the familiar Anthropic SDK to access Claude, GPT-4, Mistral, and 200+ other models through one interface. + + + + Every response includes detailed cost information. Track spending across all providers in one dashboard. + + + + If Claude is rate-limited or unavailable, Edgee automatically routes to backup models without code changes. + + + + Monitor latency, token usage, error rates, and costs for all requests in Edgee's unified dashboard. + + + +## Complete Example + +Here's a complete application example: + + + + ```python + #!/usr/bin/env python3 + import os + from anthropic import Anthropic + + def main(): + # Initialize client + client = Anthropic( + base_url="https://api.edgee.ai/v1", + api_key=os.environ.get("EDGEE_API_KEY"), + default_headers={ + "x-edgee-tags": "production,chat-app" + } + ) + + # Chat loop + conversation = [] + print("Chat with Claude (type 'quit' to exit)") + + while True: + user_input = input("\nYou: ") + if user_input.lower() == 'quit': + break + + conversation.append({ + "role": "user", + "content": user_input + }) + + # Stream response + print("\nClaude: ", end="", flush=True) + with client.messages.stream( + model="claude-sonnet-4.5", + max_tokens=1024, + messages=conversation + ) as stream: + assistant_message = "" + for text in stream.text_stream: + print(text, end="", flush=True) + assistant_message += text + + conversation.append({ + "role": "assistant", + "content": assistant_message + }) + + if __name__ == "__main__": + main() + ``` + + + + ```typescript + import Anthropic from '@anthropic-ai/sdk'; + import * as readline from 'readline'; + + async function main() { + // Initialize client + const client = new Anthropic({ + baseURL: 'https://api.edgee.ai/v1', + apiKey: process.env.EDGEE_API_KEY, + defaultHeaders: { + 'x-edgee-tags': 'production,chat-app' + } + }); + + const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout + }); + + const conversation: Array<{ role: string; content: string }> = []; + + console.log("Chat with Claude (type 'quit' to exit)"); + + const chat = () => { + rl.question('\nYou: ', async (input) => { + if (input.toLowerCase() === 'quit') { + rl.close(); + return; + } + + conversation.push({ + role: 'user', + content: input + }); + + process.stdout.write('\nClaude: '); + + const stream = await client.messages.create({ + model: 'claude-sonnet-4.5', + max_tokens: 1024, + messages: conversation, + stream: true, + }); + + let assistantMessage = ''; + for await (const event of stream) { + if (event.type === 'content_block_delta' + && event.delta.type === 'text_delta') { + process.stdout.write(event.delta.text); + assistantMessage += event.delta.text; + } + } + + conversation.push({ + role: 'assistant', + content: assistantMessage + }); + + chat(); + }); + }; + + chat(); + } + + main(); + ``` + + + +## Next Steps + +- Explore [Anthropic SDK documentation](https://docs.anthropic.com/claude/reference/getting-started-with-the-api) for advanced features +- Check out [Edgee's routing capabilities](/features/automatic-model-selection) for intelligent model selection +- Set up [observability](/features/observability) to monitor your applications +- Configure [privacy controls](/features/privacy) to manage data retention diff --git a/integrations/claude-code.mdx b/integrations/claude-code.mdx new file mode 100644 index 0000000..62f37c8 --- /dev/null +++ b/integrations/claude-code.mdx @@ -0,0 +1,192 @@ +--- +title: Claude Code +description: Use Edgee with Claude Code for building applications with Claude's official CLI tool. +icon: /images/icons/claude.svg +--- + +Claude Code is Anthropic's official CLI tool for interactive coding with AI assistance. Edgee's OpenAI-compatible API works seamlessly with Claude Code, allowing you to leverage Claude Code's powerful coding capabilities while maintaining control over your LLM infrastructure through Edgee's unified gateway. + +## Configuration + +Claude Code supports custom API endpoints through its settings. You can configure it to use Edgee as your AI provider in two ways: + +### Option 1: Environment Variables + +Set the following environment variables in your shell configuration (`~/.bashrc`, `~/.zshrc`, etc.): + +```bash +export ANTHROPIC_BASE_URL="https://api.edgee.ai/v1" +export ANTHROPIC_API_KEY="sk-edgee-..." +``` + +Then restart your terminal or run: + +```bash +source ~/.zshrc # or ~/.bashrc +``` + +### Option 2: Claude Code Settings + +You can also configure Claude Code through its settings file. Create or edit `~/.claude/settings.json`: + +```json +{ + "apiEndpoint": "https://api.edgee.ai/v1", + "apiKey": "sk-edgee-..." +} +``` + + + Make sure to replace `"sk-edgee-..."` with your actual Edgee API key from the [Edgee Console](https://www.edgee.cloud). + + +## Usage + +Once configured, Claude Code will automatically route all requests through Edgee. You can use Claude Code normally: + +```bash +# Start an interactive session +claude + +# Ask a question directly +claude "How do I implement a binary search tree in Python?" + +# Work on a specific file +claude --file src/main.py "Add error handling to this code" +``` + +## Model Selection + +When using Edgee with Claude Code, you can specify which Claude model to use through Edgee's model routing. By default, Claude Code uses the latest Claude model, but you can configure specific models: + +```bash +# Use a specific Claude model +claude --model claude-sonnet-4.5 "Explain this codebase" + +# Use different providers through Edgee +claude --model gpt-4o "Refactor this function" +``` + +## Advanced Configuration + +### Custom Headers + +You can add custom headers for analytics and filtering by setting additional environment variables: + +```bash +export ANTHROPIC_HEADERS='{"x-edgee-tags": "development,claude-code,team-backend"}' +``` + +### Tags for Observability + +Tags help you categorize and filter requests in Edgee's analytics dashboard: + +```json +{ + "apiEndpoint": "https://api.edgee.ai/v1", + "apiKey": "sk-edgee-...", + "customHeaders": { + "x-edgee-tags": "production,claude-code,user-123" + } +} +``` + + + Tags are comma-separated strings that appear in your Edgee observability dashboard, making it easy to track Claude Code usage separately from other applications. + + +## Streaming Responses + +Claude Code automatically handles streaming responses. When using Edgee, streaming works seamlessly: + +- Real-time token streaming for faster perceived response times +- Proper handling of connection errors with automatic failover +- Full observability of streaming metrics in Edgee dashboard + +## Authentication + +Edgee uses standard Bearer token authentication. Your API key is automatically formatted as: + +``` +Authorization: Bearer {sk-edgee-...} +``` + +To get your API key: + +1. Go to [Edgee Console](https://www.edgee.cloud) +2. Navigate to **API Keys** +3. Create a new key or use an existing one + +## Benefits of Using Claude Code with Edgee + + + + Access multiple LLM providers through Edgee while using Claude Code's powerful CLI interface. + + + + Track costs in real-time and set budget alerts for your Claude Code usage through Edgee's dashboard. + + + + If Claude API is down or rate-limited, Edgee can automatically route to backup models without interrupting your workflow. + + + + Monitor all Claude Code sessions with detailed metrics: latency, token usage, costs, and error rates. + + + +## Troubleshooting + +### Connection Issues + +If Claude Code cannot connect to Edgee: + +1. Verify your API key is correct +2. Check that the base URL is set to `https://api.edgee.ai/v1` +3. Ensure you have internet connectivity +4. Check [Edgee's status page](https://status.edgee.cloud) + +### Authentication Errors + +If you receive authentication errors: + +```bash +# Test your API key with curl +curl https://api.edgee.ai/v1/chat/completions \ + -H "Authorization: Bearer $ANTHROPIC_API_KEY" \ + -H "Content-Type: application/json" \ + -d '{ + "model": "claude-sonnet-4.5", + "messages": [{"role": "user", "content": "Hello!"}] + }' +``` + +If this fails, your API key may be invalid or expired. Generate a new one from the [Edgee Console](https://www.edgee.cloud). + +## Example Workflow + +Here's a complete workflow for setting up Claude Code with Edgee: + +```bash +# 1. Set environment variables +export ANTHROPIC_BASE_URL="https://api.edgee.ai/v1" +export ANTHROPIC_API_KEY="sk-edgee-..." + +# 2. Test the connection +claude "Hello, Edgee!" + +# 3. Start coding with full observability +claude --file src/app.py "Add comprehensive error handling" + +# 4. Check usage in Edgee Console +# Visit https://www.edgee.cloud to see real-time metrics +``` + +## Next Steps + +- Explore [Claude Code's documentation](https://claude.com/claude-code) for advanced features +- Check out [Edgee's routing capabilities](/features/automatic-model-selection) for intelligent model selection +- Set up [observability](/features/observability) to monitor your Claude Code sessions +- Configure [privacy controls](/features/privacy) for sensitive codebases diff --git a/integrations/openai-sdk.mdx b/integrations/openai-sdk.mdx new file mode 100644 index 0000000..a7c855b --- /dev/null +++ b/integrations/openai-sdk.mdx @@ -0,0 +1,333 @@ +--- +title: OpenAI SDK +sidebarTitle: OpenAI SDK +description: Using Edgee with OpenAI SDK +icon: /images/icons/openai.svg +--- + +Edgee provides an **OpenAI-compatible API**, which means you can use the official OpenAI SDKs for TypeScript and Python with Edgee. This allows you to leverage Edgee's routing, observability, and cost tracking features without changing your existing code. + +## Why Use OpenAI SDK with Edgee? + +- **No Code Changes**: Use your existing OpenAI SDK code as-is +- **Multi-Provider Access**: Route to OpenAI, Anthropic, Google, and more through one API +- **Automatic Failover**: Built-in reliability with fallback providers +- **Cost Tracking**: Real-time visibility into token usage and costs +- **Observability**: Request tracing and logging across all providers + +## Installation + +Install the OpenAI SDK for your preferred language: + + + + ```bash + npm install openai + ``` + + + ```bash + pip install openai + ``` + + + +## Configuration + +Configure the OpenAI SDK to use Edgee's API endpoint: + + + +```typescript title="TypeScript" +import OpenAI from "openai"; + +const openai = new OpenAI({ + baseURL: "https://api.edgee.ai/v1", + apiKey: process.env.EDGEE_API_KEY, // Your Edgee API key +}); + +async function main() { + const completion = await openai.chat.completions.create({ + model: "gpt-4o", + messages: [ + { role: "user", content: "What is the capital of France?" } + ], + }); + + console.log(completion.choices[0].message.content); +} + +main(); +``` + +```python title="Python" +from openai import OpenAI +from os import getenv + +# Configure OpenAI SDK to use Edgee +client = OpenAI( + base_url="https://api.edgee.ai/v1", + api_key=getenv("EDGEE_API_KEY"), # Your Edgee API key +) + +completion = client.chat.completions.create( + model="gpt-4o", + messages=[ + { + "role": "user", + "content": "What is the capital of France?", + }, + ], +) + +print(completion.choices[0].message.content) +``` + + + +## Advanced Usage + +### Function Calling (Tools) + +Edgee fully supports OpenAI's function calling interface: + + + +```typescript title="TypeScript" +import OpenAI from "openai"; + +const openai = new OpenAI({ + baseURL: "https://api.edgee.ai/v1", + apiKey: process.env.EDGEE_API_KEY, +}); + +async function main() { + const completion = await openai.chat.completions.create({ + model: "gpt-4o", + messages: [ + { role: "user", content: "What's the weather in Paris?" } + ], + tools: [ + { + type: "function", + function: { + name: "get_weather", + description: "Get the current weather for a location", + parameters: { + type: "object", + properties: { + location: { + type: "string", + description: "City name", + }, + }, + required: ["location"], + }, + }, + }, + ], + tool_choice: "auto", + }); + + if (completion.choices[0].message.tool_calls) { + console.log("Tool calls:", completion.choices[0].message.tool_calls); + } else { + console.log("Response:", completion.choices[0].message.content); + } +} + +main(); +``` + +```python title="Python" +from openai import OpenAI +from os import getenv + +client = OpenAI( + base_url="https://api.edgee.ai/v1", + api_key=getenv("EDGEE_API_KEY"), +) + +completion = client.chat.completions.create( + model="gpt-4o", + messages=[ + { + "role": "user", + "content": "What's the weather in Paris?", + }, + ], + tools=[ + { + "type": "function", + "function": { + "name": "get_weather", + "description": "Get the current weather for a location", + "parameters": { + "type": "object", + "properties": { + "location": { + "type": "string", + "description": "City name", + }, + }, + "required": ["location"], + }, + }, + }, + ], + tool_choice="auto", +) + +if completion.choices[0].message.tool_calls: + print("Tool calls:", completion.choices[0].message.tool_calls) +else: + print("Response:", completion.choices[0].message.content) +``` + + + +### Tags + +You can add tags to your requests for analytics and filtering using the `x-edgee-tags` header: + + + +```typescript title="TypeScript" +import OpenAI from "openai"; + +const openai = new OpenAI({ + baseURL: "https://api.edgee.ai/v1", + apiKey: process.env.EDGEE_API_KEY, + defaultHeaders: { + "x-edgee-tags": "production,user-123,summarization", + }, +}); + +// All requests will include these tags +const completion = await openai.chat.completions.create({ + model: "gpt-4o", + messages: [ + { role: "user", content: "What is the capital of France?" } + ], +}); +``` + +```python title="Python" +from openai import OpenAI +from os import getenv + +# Tags applied to all requests via default headers +client = OpenAI( + base_url="https://api.edgee.ai/v1", + api_key=getenv("EDGEE_API_KEY"), + default_headers={ + "x-edgee-tags": "production,user-123,summarization", + }, +) + +# Or per-request using extra_headers +completion = client.chat.completions.create( + model="gpt-4o", + messages=[ + {"role": "user", "content": "What is the capital of France?"}, + ], + extra_headers={ + "x-edgee-tags": "one-off-tag,experiment", + }, +) +``` + + + + + Tags are comma-separated strings in the header. They help you categorize and filter requests in Edgee's analytics dashboard. + + +### Streaming Responses + +Edgee supports streaming responses for real-time token delivery: + + + +```typescript title="TypeScript" +import OpenAI from "openai"; + +const openai = new OpenAI({ + baseURL: "https://api.edgee.ai/v1", + apiKey: process.env.EDGEE_API_KEY, +}); + +async function main() { + const stream = await openai.chat.completions.create({ + model: "gpt-4o", + messages: [ + { role: "user", content: "Tell me a short story" } + ], + stream: true, + }); + + for await (const chunk of stream) { + const content = chunk.choices[0]?.delta?.content || ""; + process.stdout.write(content); + } +} + +main(); +``` + +```python title="Python" +from openai import OpenAI +from os import getenv + +client = OpenAI( + base_url="https://api.edgee.ai/v1", + api_key=getenv("EDGEE_API_KEY"), +) + +stream = client.chat.completions.create( + model="gpt-4o", + messages=[ + { + "role": "user", + "content": "Tell me a short story", + }, + ], + stream=True, +) + +for chunk in stream: + content = chunk.choices[0].delta.content or "" + print(content, end="", flush=True) +``` + + + + +## Migration from OpenAI + +If you're already using the OpenAI SDK, migrating to Edgee is straightforward: + +1. **Change the base URL**: Update `baseURL` from `https://api.openai.com/v1` to `https://api.edgee.ai/v1` +2. **Update API key**: Use your Edgee API key instead of your OpenAI key +3. **That's it!** Your existing code will work without any other changes + + + All OpenAI SDK features are supported, including streaming, function calling, and response formatting. Edgee maintains full compatibility with the OpenAI API specification. + + +## What's Next? + + + + Create an account and get your Edgee API key to start using the OpenAI SDK. + + + Browse 200+ models available through Edgee from multiple providers. + + + Check out the native Edgee SDKs for TypeScript, Python, Go, and Rust. + + + Explore the full REST API documentation. + + \ No newline at end of file