Why Use OpenAI SDK with Edgee?
- Up to 50% Cost Reduction: Automatic token compression when enabled via headers or console
- 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 in the Edgee dashboard
- Observability: Request tracing, compression metrics, and logging across all providers
Installation
Install the OpenAI SDK for your preferred language:- TypeScript
- Python
Configuration
Configure the OpenAI SDK to use Edgee’s API endpoint:Token Usage Tracking
Access standard OpenAI token usage metrics in every response:When compression is enabled,
prompt_tokens reflects the compressed token count. View detailed compression metrics in the Edgee dashboard.Compression & Tags via Headers
When using the OpenAI SDK with Edgee, you can control token compression and add tags using HTTP headers:Enabling Compression
Adding Tags for Analytics
Combine compression with tags to track requests in your dashboard:| Header | Type | Description |
|---|---|---|
x-edgee-enable-compression | "true" or "false" | Enable token compression for requests (overrides console settings) |
x-edgee-compression-rate | string | Target compression rate (0.0-1.0, default 0.75) |
x-edgee-tags | string | Comma-separated tags for analytics and filtering |
Advanced Usage
Function Calling (Tools)
Edgee fully supports OpenAI’s function calling interface:Streaming Responses
Edgee supports streaming responses for real-time token delivery:Migration from OpenAI
If you’re already using the OpenAI SDK, migrating to Edgee is straightforward:- Change the base URL: Update
baseURLfromhttps://api.openai.com/v1tohttps://api.edgee.ai/v1 - Update API key: Use your Edgee API key instead of your OpenAI key
- That’s it! Your existing code will work without any other changes
What’s Next?
Get API Key
Create an account and get your Edgee API key to start using the OpenAI SDK.
Supported Models
Browse 200+ models available through Edgee from multiple providers.
Edgee SDK
Check out the native Edgee SDKs for TypeScript, Python, Go, and Rust.
API Reference
Explore the full REST API documentation.