Skip to main content

OpenAI SDK Usage

MixRoute is fully compatible with the official OpenAI SDK. Simply change the base URL to use MixRoute with your existing OpenAI SDK code.

Installation

Configuration

Python

Node.js / TypeScript

Go

Chat Completions

Basic Usage

Streaming

Node.js Streaming

Using Different Models

Mixroute Api supports models from multiple providers using the same SDK:

Base64 Image

Function Calling

Embeddings

Batch Embeddings

Image Generation

List Models

Error Handling

Async Usage

Environment Variables

Set environment variables instead of hardcoding:

Best Practices

  • Use environment variables for API keys
  • Implement retry logic for transient errors
  • Use streaming for better UX with long responses
  • Batch requests when processing multiple items
  • Monitor usage to stay within rate limits