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
| Header | Type | Description |
|---|---|---|
x-edgee-compression-model | "claude", "opencode", "cursor", "codex" | Compression bundle to apply (e.g. “claude” for Claude Token Compression) |
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://edgee.io/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