Skip to main content

Python (OpenAI SDK)

Use the official OpenAI Python SDK with Eden AI to access 200+ AI models through a familiar interface.

Overview

The OpenAI Python SDK is fully compatible with Eden AI’s V3 API. Simply point the SDK to Eden AI’s endpoint and you can access models from OpenAI, Anthropic, Google, Cohere, Meta, and more.

Installation

Install the OpenAI Python SDK:

Quick Start

Configure the OpenAI client to use Eden AI:

Available Models

Access models from multiple providers using the provider/model format:

OpenAI

  • openai/gpt-4
  • openai/gpt-4-turbo
  • openai/gpt-4o
  • openai/gpt-3.5-turbo

Anthropic

  • anthropic/claude-3-5-sonnet-20241022
  • anthropic/claude-3-opus-20240229
  • anthropic/claude-3-sonnet-20240229
  • anthropic/claude-3-haiku-20240307

Google

  • google/gemini-pro
  • google/gemini-1.5-pro
  • google/gemini-1.5-flash

Cohere

  • cohere/command-r-plus
  • cohere/command-r

Meta

  • meta/llama-3-70b
  • meta/llama-3-8b

Multi-Turn Conversations

Build conversational applications with message history:

Advanced Parameters

Control model behavior with standard OpenAI parameters:

Vision Capabilities

Send images to vision-capable models:

Async Support

Use async/await for concurrent requests:

Error Handling

Handle API errors gracefully:

Complete Example

A full example with conversation management:

List Available Models

Discover available models programmatically:

Environment Variables

Store your API key securely using environment variables: Use with python-dotenv:

Troubleshooting

Authentication Errors

Ensure your API key is correct and has the Bearer prefix when using raw requests:
headers = {"Authorization": f"Bearer {api_key}"}

Rate Limiting

If you hit rate limits, implement exponential backoff:

Streaming Issues

Make sure stream=True is set:
# Correct
stream = client.chat.completions.create(..., stream=True)

# V3 requires streaming

Next Steps