Provider Setup Guide

Detailed setup instructions for each provider supported by OneLLM.

Table of Contents


OpenAI

1. Get API Key

  1. Go to platform.openai.com
  2. Sign up or log in
  3. Navigate to API Keys
  4. Create new secret key

2. Set Environment Variable

export OPENAI_API_KEY="sk-..."

3. Test Connection

from onellm import OpenAI

client = OpenAI()
response = client.chat.completions.create(
    model="openai/gpt-4o-mini",
    messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message['content'])

Available Models

  • openai/gpt-4o - Most capable
  • openai/gpt-4o-mini - Faster, cheaper
  • openai/gpt-4-turbo - Previous generation
  • openai/gpt-3.5-turbo - Legacy, fast

Anthropic

1. Get API Key

  1. Go to console.anthropic.com
  2. Sign up for access
  3. Navigate to API Keys
  4. Generate key

2. Set Environment Variable

export ANTHROPIC_API_KEY="sk-ant-..."

3. Test Connection

response = client.chat.completions.create(
    model="anthropic/claude-3-5-sonnet-20241022",
    messages=[{"role": "user", "content": "Hello!"}]
)

Available Models

  • anthropic/claude-3-5-sonnet-20241022 - Latest, most capable
  • anthropic/claude-3-opus-20240229 - Powerful, expensive
  • anthropic/claude-3-sonnet-20240229 - Balanced
  • anthropic/claude-3-haiku-20240307 - Fast, cheap

Google AI Studio

1. Get API Key

  1. Go to makersuite.google.com
  2. Sign in with Google account
  3. Get API key from settings

2. Set Environment Variable

export GOOGLE_API_KEY="..."

3. Test Connection

response = client.chat.completions.create(
    model="google/gemini-1.5-flash",
    messages=[{"role": "user", "content": "Hello!"}]
)

Available Models

  • google/gemini-1.5-pro - Most capable, 1M context
  • google/gemini-1.5-flash - Fast, efficient
  • google/gemini-pro - Previous generation

Mistral

1. Get API Key

  1. Go to console.mistral.ai
  2. Create account
  3. Navigate to API Keys
  4. Create new key

2. Set Environment Variable

export MISTRAL_API_KEY="..."

3. Test Connection

response = client.chat.completions.create(
    model="mistral/mistral-small-latest",
    messages=[{"role": "user", "content": "Hello!"}]
)

Available Models

  • mistral/mistral-large-latest - Most capable
  • mistral/mistral-medium-latest - Balanced
  • mistral/mistral-small-latest - Fast
  • mistral/mistral-tiny - Fastest

Groq

1. Get API Key

  1. Go to console.groq.com
  2. Sign up for access
  3. Get API key from dashboard

2. Set Environment Variable

export GROQ_API_KEY="gsk_..."

3. Test Connection

response = client.chat.completions.create(
    model="groq/llama3-70b-8192",
    messages=[{"role": "user", "content": "Hello!"}]
)

Available Models

  • groq/llama3-70b-8192 - Llama 3 70B
  • groq/llama3-8b-8192 - Llama 3 8B
  • groq/mixtral-8x7b-32768 - Mixtral MoE
  • groq/gemma-7b-it - Google Gemma

Together AI

1. Get API Key

  1. Go to api.together.xyz
  2. Sign up
  3. Get API key from account

2. Set Environment Variable

export TOGETHER_API_KEY="..."

3. Test Connection

response = client.chat.completions.create(
    model="together/meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo",
    messages=[{"role": "user", "content": "Hello!"}]
)

Available Models

  • Various Llama models
  • Mistral models
  • CodeLlama models
  • 50+ open source models

Fireworks

1. Get API Key

  1. Go to app.fireworks.ai
  2. Create account
  3. Get API key

2. Set Environment Variable

export FIREWORKS_API_KEY="..."

3. Test Connection

response = client.chat.completions.create(
    model="fireworks/accounts/fireworks/models/llama-v3p1-70b-instruct",
    messages=[{"role": "user", "content": "Hello!"}]
)

Anyscale

1. Get API Key

  1. Go to anyscale.com
  2. Sign up for Endpoints
  3. Get API key (starts with esecret_)

2. Set Environment Variable

export ANYSCALE_API_KEY="esecret_..."

3. Test Connection

response = client.chat.completions.create(
    model="anyscale/llama3-70b",
    messages=[{"role": "user", "content": "Hello!"}]
)

X.AI

1. Get API Key

  1. Go to x.ai
  2. Request access
  3. Get API key when approved

2. Set Environment Variable

export XAI_API_KEY="..."

3. Test Connection

response = client.chat.completions.create(
    model="xai/grok-2-latest",
    messages=[{"role": "user", "content": "Hello!"}]
)

Perplexity

1. Get API Key

  1. Go to perplexity.ai/settings/api
  2. Sign up
  3. Generate API key

2. Set Environment Variable

export PERPLEXITY_API_KEY="pplx-..."

3. Test Connection

response = client.chat.completions.create(
    model="perplexity/llama-3.1-sonar-small-128k-online",
    messages=[{"role": "user", "content": "What's happening today?"}]
)

DeepSeek

1. Get API Key

  1. Go to platform.deepseek.com
  2. Register account
  3. Get API key

2. Set Environment Variable

export DEEPSEEK_API_KEY="..."

3. Test Connection

response = client.chat.completions.create(
    model="deepseek/deepseek-chat",
    messages=[{"role": "user", "content": "你好!"}]
)

Cohere

1. Get API Key

  1. Go to dashboard.cohere.com
  2. Sign up
  3. Get API key

2. Set Environment Variable

export COHERE_API_KEY="..."

3. Test Connection

response = client.chat.completions.create(
    model="cohere/command-r-plus",
    messages=[{"role": "user", "content": "Hello!"}]
)

OpenRouter

1. Get API Key

  1. Go to openrouter.ai
  2. Sign up
  3. Get API key from dashboard

2. Set Environment Variable

export OPENROUTER_API_KEY="sk-or-..."

3. Test Connection

# Access 100+ models
response = client.chat.completions.create(
    model="openrouter/meta-llama/llama-3.2-3b-instruct:free",
    messages=[{"role": "user", "content": "Hello!"}]
)

Azure OpenAI

1. Setup Azure Resources

  1. Create Azure account
  2. Create OpenAI resource
  3. Deploy models
  4. Get endpoint and key

2. Create Configuration File

Create azure.json:

{
    "endpoint": "https://your-resource.openai.azure.com",
    "api_key": "your-key",
    "api_version": "2024-02-01",
    "deployments": {
        "gpt-4": "your-gpt4-deployment-name",
        "gpt-35-turbo": "your-gpt35-deployment-name"
    }
}

3. Test Connection

client = OpenAI(azure_config_path="azure.json")
response = client.chat.completions.create(
    model="azure/gpt-4",
    messages=[{"role": "user", "content": "Hello!"}]
)

AWS Bedrock

1. Setup AWS

  1. Create AWS account
  2. Enable Bedrock models
  3. Configure IAM permissions

2. Create Configuration File

Create bedrock.json:

{
    "region": "us-east-1",
    "aws_access_key_id": "AKIA...",
    "aws_secret_access_key": "..."
}

3. Test Connection

response = client.chat.completions.create(
    model="bedrock/claude-3-sonnet",
    messages=[{"role": "user", "content": "Hello!"}]
)

Google Vertex AI

1. Setup GCP

  1. Create GCP project
  2. Enable Vertex AI API
  3. Create service account
  4. Download credentials JSON

2. Set Environment Variable

export GOOGLE_APPLICATION_CREDENTIALS="path/to/service-account.json"

3. Test Connection

response = client.chat.completions.create(
    model="vertexai/gemini-1.5-flash",
    messages=[{"role": "user", "content": "Hello!"}]
)

Ollama

1. Install Ollama

# macOS/Linux
curl -fsSL https://ollama.com/install.sh | sh

# Windows
# Download from ollama.com

2. Pull Models

ollama pull llama3
ollama pull mistral

3. Test Connection

# Default localhost
response = client.chat.completions.create(
    model="ollama/llama3",
    messages=[{"role": "user", "content": "Hello!"}]
)

# Custom endpoint
response = client.chat.completions.create(
    model="ollama/llama3@192.168.1.100:11434",
    messages=[{"role": "user", "content": "Hello!"}]
)

llama.cpp

1. Install Dependencies

pip install llama-cpp-python

2. Download Models

# Using OneLLM's utility
onellm download llama-3-8b

# Or manually download GGUF files
wget https://huggingface.co/model.gguf

3. Set Model Directory

export LLAMA_CPP_MODEL_DIR="/path/to/models"

4. Test Connection

response = client.chat.completions.create(
    model="llama_cpp/llama-3-8b-instruct.gguf",
    messages=[{"role": "user", "content": "Hello!"}]
)

GPU Acceleration

# Configure GPU layers
client = OpenAI(
    llama_cpp_config={
        "n_gpu_layers": 35,  # Number of layers on GPU
        "n_ctx": 4096        # Context window
    }
)

Troubleshooting

API Key Issues

  • Ensure key is set correctly
  • Check for extra spaces/quotes
  • Verify key hasn’t expired
  • Try regenerating key

Connection Issues

  • Check internet connection
  • Verify firewall settings
  • Try different regions (if applicable)
  • Check service status pages

Model Access

  • Ensure model is available in your region
  • Check if model requires special access
  • Verify billing is set up
  • Check quota limits

Next Steps


Back to top

Copyright © 2025 Ran Aroussi.
Licensed under Apache 2.0 license.