Skip to main content
The official OpenAI Python SDK works seamlessly with Codex-LB. Simply point it at Codex-LB’s /v1 endpoint to leverage account pooling and usage tracking.

Endpoint

The OpenAI SDK uses the standard OpenAI-compatible /v1 endpoint.

Installation

Install the OpenAI Python SDK:

Basic Usage

When API key authentication is disabled (default):
The OpenAI SDK requires an api_key parameter. When auth is disabled, any string value works.

Complete Example

Here’s a complete example with error handling:

Streaming Responses

Stream responses for real-time output:

Advanced Features

Async Client

Use the async client for concurrent requests:

Function Calling

Use function calling (tools) for structured outputs:

Vision (Image Input)

Send images to vision-capable models:

Configuration Options

Example with custom config:

Verify Configuration

Test your connection:

Troubleshooting

Ensure Codex-LB is running:
If using Docker:
API key auth is enabled but your key is missing or invalid:
  1. Verify the key is valid in the dashboard
  2. Ensure you’re reading from the correct environment variable
  3. Check the key hasn’t expired
The requested model isn’t available:
  1. Verify the model ID matches exactly (case-sensitive)
  2. Ensure at least one account supports the model
  3. Check model sync in dashboard settings
Increase the timeout for long-running requests:
You’re hitting rate limits:
  1. Check your API key limits in the dashboard
  2. Implement exponential backoff:
  3. Add more accounts to the pool

Remote Access

If Codex-LB is running on a different machine:
When exposing Codex-LB remotely:
  • Always enable API key authentication
  • Use HTTPS with a reverse proxy (nginx, Caddy)
  • Configure firewall rules to restrict access
  • See Production Deployment

Next Steps

API Keys

Create and manage API keys for authentication

Rate Limiting

Configure rate limits per key or account

Chat Completions API

Full API reference for /v1/chat/completions

Usage Tracking

Monitor SDK usage in the dashboard