HiveOps Logo
HiveOps
/Migration from OpenAI

Migration from OpenAI

Switch from OpenAI to HiveOps

Migrating from OpenAI to HiveOps

Switch from OpenAI's API to HiveOps in minutes. Same SDKs, same code structure, just better pricing.

Why Migrate?

FeatureOpenAIHiveOpsSavings
GPT-5.4 mini equivalent$0.75/$4.50 per 1M tokens$0.15/$0.55 (Llama 3 8B)87% cheaper
GPT-5.4 equivalent$2.50/$15 per 1M tokens$1.15/$4.75 (Llama 3 70B)77% cheaper
Open-source models✅ Llama 3, Gemma 2, Mistral-
No training on your data⚠️ Opt-out✅ Default-
Streaming-
Function calling-
JSON mode-

Quick Start: 3-Step Migration

Step 1: Get Your HiveOps API Key

  1. Sign up at hiveops.io (free $10 credit)
  2. Verify your email
  3. Go to Dashboard → API Keys
  4. Click Create New Key and copy it

Step 2: Update Your Code

Python:

from openai import OpenAI

# Old
client = OpenAI(api_key="sk-...YOUR_OPENAI_KEY...")

# New - just change these two lines
client = OpenAI(
    api_key="sk-...YOUR_HIVEOPS_KEY...",
    base_url="https://ai.hiveops.io"
)

# All your existing code works as-is!
response = client.chat.completions.create(
    model="llama3:8b-instruct-q8_0",  # Change model name
    messages=[{"role": "user", "content": "Hello!"}]
)

JavaScript/TypeScript:

import OpenAI from "openai";

// Old
const client = new OpenAI({ apiKey: "sk-...YOUR_OPENAI_KEY..." });

// New - just change these two properties
const client = new OpenAI({
  apiKey: "sk-...YOUR_HIVEOPS_KEY...",
  baseURL: "https://ai.hiveops.io",
});

// All your existing code works!
const response = await client.chat.completions.create({
  model: "llama3:8b-instruct-q8_0", // Change model name
  messages: [{ role: "user", content: "Hello!" }],
});

Step 3: Map Your Models

OpenAI ModelHiveOps AlternativeUse Case
gpt-3.5-turbollama3:8b-instruct-q8_0Fast, general-purpose
gpt-4llama3:70b-instruct-q8_0Complex reasoning
gpt-3.5-turbo-0125gemma2:9b-instruct-q8_0Balanced performance
gpt-3.5-turbo-instructmistral:7b-instruct-v0.3-q8_0Budget-friendly

That's it! Your application now uses HiveOps.


Detailed Migration Guide

Environment Variables

Update your .env file:

# Old
OPENAI_API_KEY=sk-...YOUR_OPENAI_KEY...

# New
OPENAI_API_KEY=sk-...YOUR_HIVEOPS_KEY...
OPENAI_BASE_URL=https://ai.hiveops.io

Most OpenAI SDKs respect the OPENAI_BASE_URL environment variable.

Configuration Files

Python (config.py):

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.getenv("OPENAI_API_KEY"),
    base_url=os.getenv("OPENAI_BASE_URL", "https://ai.hiveops.io")
)

TypeScript (config.ts):

import OpenAI from "openai";

export const client = new OpenAI({
  apiKey: process.env.OPENAI_API_KEY!,
  baseURL: process.env.OPENAI_BASE_URL || "https://ai.hiveops.io",
});

Feature Comparison

Chat Completions

✅ Fully Compatible

# This code works identically on both platforms
response = client.chat.completions.create(
    model="llama3:8b-instruct-q8_0",  # Just change model name
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Tell me a joke."}
    ],
    temperature=0.7,
    max_tokens=500
)

Streaming

✅ Fully Compatible

stream = client.chat.completions.create(
    model="llama3:8b-instruct-q8_0",
    messages=[{"role": "user", "content": "Count to 10"}],
    stream=True
)

for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="")

Function Calling

✅ Fully Compatible

tools = [
    {
        "type": "function",
        "function": {
            "name": "get_weather",
            "description": "Get current weather",
            "parameters": {
                "type": "object",
                "properties": {
                    "location": {"type": "string"}
                },
                "required": ["location"]
            }
        }
    }
]

response = client.chat.completions.create(
    model="llama3:8b-instruct-q8_0",
    messages=[{"role": "user", "content": "What's the weather in NYC?"}],
    tools=tools
)

JSON Mode

✅ Fully Compatible

response = client.chat.completions.create(
    model="llama3:8b-instruct-q8_0",
    messages=[
        {"role": "system", "content": "You output JSON."},
        {"role": "user", "content": "List 3 programming languages."}
    ],
    response_format={"type": "json_object"}
)

Async/Await

✅ Fully Compatible

import asyncio
from openai import AsyncOpenAI

async_client = AsyncOpenAI(
    api_key="sk-YOUR-HIVEOPS-KEY",
    base_url="https://ai.hiveops.io"
)

async def main():
    response = await async_client.chat.completions.create(
        model="llama3:8b-instruct-q8_0",
        messages=[{"role": "user", "content": "Hello!"}]
    )
    print(response.choices[0].message.content)

asyncio.run(main())

Framework Integration

LangChain

Python:

from langchain_openai import ChatOpenAI

# Old
llm = ChatOpenAI(model="gpt-3.5-turbo")

# New - add openai_api_base
llm = ChatOpenAI(
    model="llama3:8b-instruct-q8_0",
    openai_api_base="https://ai.hiveops.io",
    openai_api_key="sk-YOUR-HIVEOPS-KEY"
)

# Everything else works the same
response = llm.invoke("Tell me a joke")

TypeScript:

import { ChatOpenAI } from "@langchain/openai";

const llm = new ChatOpenAI({
  modelName: "llama3:8b-instruct-q8_0",
  openAIApiKey: "sk-YOUR-HIVEOPS-KEY",
  configuration: {
    baseURL: "https://ai.hiveops.io",
  },
});

LlamaIndex

from llama_index.llms.openai import OpenAI

llm = OpenAI(
    model="llama3:8b-instruct-q8_0",
    api_key="sk-YOUR-HIVEOPS-KEY",
    api_base="https://ai.hiveops.io"
)

CrewAI

from crewai import Agent, Task, Crew
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="llama3:8b-instruct-q8_0",
    openai_api_base="https://ai.hiveops.io",
    openai_api_key="sk-YOUR-HIVEOPS-KEY"
)

agent = Agent(
    role="Research Assistant",
    llm=llm,
    goal="Find information about AI"
)

Testing Your Migration

1. Side-by-Side Test

Keep both clients and compare outputs:

from openai import OpenAI

openai_client = OpenAI(api_key="sk-OPENAI-KEY")
hiveops_client = OpenAI(
    api_key="sk-HIVEOPS-KEY",
    base_url="https://ai.hiveops.io"
)

prompt = [{"role": "user", "content": "Explain quantum computing in one sentence."}]

openai_response = openai_client.chat.completions.create(
    model="gpt-3.5-turbo",
    messages=prompt
)

hiveops_response = hiveops_client.chat.completions.create(
    model="llama3:8b-instruct-q8_0",
    messages=prompt
)

print("OpenAI:", openai_response.choices[0].message.content)
print("HiveOps:", hiveops_response.choices[0].message.content)

2. Gradual Rollout

Use feature flags to route a percentage of requests to HiveOps:

import random

def get_client():
    if random.random() < 0.10:  # 10% to HiveOps
        return OpenAI(
            api_key="sk-HIVEOPS-KEY",
            base_url="https://ai.hiveops.io"
        ), "llama3:8b-instruct-q8_0"
    else:
        return OpenAI(api_key="sk-OPENAI-KEY"), "gpt-3.5-turbo"

client, model = get_client()
response = client.chat.completions.create(model=model, messages=messages)

3. Monitor Usage

Track token usage to verify cost savings:

response = client.chat.completions.create(...)

tokens = response.usage.total_tokens
# Llama 3 8B: $0.01 per 1M input, $0.02 per 1M output
estimated_cost = (
    response.usage.prompt_tokens / 1_000_000 * 0.01 +
    response.usage.completion_tokens / 1_000_000 * 0.02
)

print(f"Tokens: {tokens}, Cost: ${estimated_cost:.6f}")

Common Migration Issues

Issue 1: Model Name Not Recognized

Problem:

Error: Model 'gpt-3.5-turbo' not found

Solution: Update to a HiveOps model:

# Change this
model="gpt-3.5-turbo"

# To this
model="llama3:8b-instruct-q8_0"

See model mapping table above.

Issue 2: API Key Format

Problem:

Error: Invalid API key format

Solution: Make sure you're using your HiveOps API key (starts with sk-), not your OpenAI key.

Issue 3: Base URL Not Set

Problem: Requests still going to OpenAI

Solution: Explicitly set base_url:

client = OpenAI(
    api_key="sk-HIVEOPS-KEY",
    base_url="https://ai.hiveops.io"  # Don't forget this!
)

Issue 4: Library Version

Problem:

TypeError: OpenAI() got an unexpected keyword argument 'base_url'

Solution: Update to the latest OpenAI SDK:

pip install --upgrade openai  # Python
npm install openai@latest     # JavaScript

Requires:

  • Python: openai>=1.0.0
  • JavaScript: openai>=4.0.0

Performance Considerations

Latency

  • HiveOps average latency: 200-500ms
  • OpenAI average latency: 500-1500ms
  • HiveOps is typically faster due to decentralized infrastructure

Throughput

  • Rate limits: 60 requests/min, 150K tokens/min
  • For higher limits, contact [email protected]

Model Differences

Open-source models have different characteristics:

AspectGPT-3.5Llama 3 8B
SpeedMediumFast
QualityHighHigh
CreativityHighMedium-High
ReasoningGoodVery Good
CodeVery GoodExcellent

Recommendation: Test with your specific use case to validate quality.


Cost Calculator

Estimate your savings by switching to HiveOps:

Your UsageOpenAI (GPT-3.5)HiveOps (Llama 3 8B)Savings
1M tokens/day$15/day (~$450/mo)$0.30/day (~$9/mo)$441/mo (98%)
10M tokens/day$150/day (~$4,500/mo)$3/day (~$90/mo)$4,410/mo (98%)
100M tokens/day$1,500/day (~$45,000/mo)$30/day (~$900/mo)$44,100/mo (98%)

Assumes 50/50 input/output token split

Example: If you process 5M tokens/day on GPT-3.5:

  • OpenAI cost: ~$2,250/month
  • HiveOps cost: ~$45/month
  • Your savings: ~$2,205/month

Rollback Plan

If you need to switch back to OpenAI:

1. Keep your OpenAI API key active during testing

2. Use environment variables for easy switching:

# Switch to HiveOps
export OPENAI_BASE_URL=https://ai.hiveops.io

# Switch back to OpenAI
unset OPENAI_BASE_URL

3. Your code stays the same - just change the environment variable.


Migration Checklist

  • Sign up for HiveOps account
  • Generate API key
  • Update environment variables
  • Map OpenAI models to HiveOps models
  • Update base_url in SDK initialization
  • Run side-by-side tests with same prompts
  • Deploy to staging environment
  • Monitor error rates and response quality
  • Gradually route production traffic (10% → 50% → 100%)
  • Monitor cost savings in dashboard
  • Update documentation for your team
  • (Optional) Cancel OpenAI subscription

Support

Need help migrating?

We offer free migration support for teams processing >10M tokens/day.