How do I point my existing OpenAI SDK to Oxen.ai’s OpenAI-compatible API (https://hub.oxen.ai/api) and choose a model?
AI Data Version Control

How do I point my existing OpenAI SDK to Oxen.ai’s OpenAI-compatible API (https://hub.oxen.ai/api) and choose a model?

6 min read

Quick Answer: You can point most existing OpenAI SDKs to Oxen.ai’s OpenAI-compatible API by changing the base_url (or equivalent) to https://hub.oxen.ai/api and swapping your api_key for an Oxen API token. Then, choose any supported model—like gpt-4o-mini, llama-3.1-70b-instruct, or your own fine-tuned model ID—and pass it via the model parameter exactly as you would with OpenAI.

Most teams discover that switching providers is less about rewriting code and more about changing a few configuration values. Oxen.ai’s OpenAI-compatible API is designed so you can keep your existing OpenAI SDK usage patterns—just update the base URL, key, and model name, then you’re ready to run prompts, call embeddings, or hit your own fine-tuned models behind Oxen’s serverless endpoints.

Key Benefits:

  • Reuse your existing OpenAI codepaths: Keep the same SDKs, request shapes, and streaming patterns—just change configuration.
  • Own your AI stack end-to-end: Point the SDK at models you control, including fine-tuned models trained on versioned Oxen datasets.
  • Scale with transparent pricing and models: Select from ~120+ models, pay as you go, and plug in custom models without new infra.

Core Concepts & Key Points

ConceptDefinitionWhy it's important
OpenAI-compatible base URLThe API host and path your existing OpenAI SDK calls instead of api.openai.com.Lets you switch to Oxen.ai without changing method signatures or response handling.
Oxen API key & authA token generated in Oxen.ai that authenticates requests to https://hub.oxen.ai/api.Replaces your OpenAI key so your app can call Oxen endpoints securely.
Model selectionChoosing which model name or endpoint ID to pass in the model field.Determines which foundation or fine-tuned model your prompts are routed to and what you pay per token/image/second.

How It Works (Step-by-Step)

At a high level, you:

  1. Generate an Oxen.ai API key.
  2. Point your OpenAI SDK’s base_url to https://hub.oxen.ai/api.
  3. Swap the model string to one of Oxen’s supported models—or your own fine-tuned model ID.

1. Generate and store your Oxen API key

  1. Sign up or log in at Oxen.ai.
  2. Navigate to your API or account settings.
  3. Create an API key (token) for programmatic access.
  4. Store it in an environment variable, e.g.:
export OXEN_API_KEY="oxen_your_token_here"

Treat this like any sensitive secret: don’t hard-code it, don’t commit it to Git.

2. Update your OpenAI SDK configuration

Below are concrete examples for common SDKs, all pointing to https://hub.oxen.ai/api.

Python (OpenAI 1.x client style)

If you’re using the newer OpenAI client:

from openai import OpenAI
import os

client = OpenAI(
    api_key=os.environ["OXEN_API_KEY"],
    base_url="https://hub.oxen.ai/api"
)

response = client.chat.completions.create(
    model="gpt-4o-mini",  # or another Oxen-supported model
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Explain dataset versioning in one paragraph."}
    ]
)

print(response.choices[0].message.content)

Key changes vs OpenAI default:

  • base_url="https://hub.oxen.ai/api"
  • api_key set to your Oxen API key
  • model set to an Oxen-available model name or your custom model ID

Node.js / TypeScript (OpenAI SDK)

import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.OXEN_API_KEY,
  baseURL: "https://hub.oxen.ai/api",
});

const response = await client.chat.completions.create({
  model: "gpt-4o-mini",
  messages: [
    { role: "system", content: "You are a helpful assistant." },
    { role: "user", content: "Summarize dataset versioning best practices." },
  ],
});

console.log(response.choices[0].message.content);

Again: same methods, same request structure—just a different baseURL, key, and model.

cURL (for quick sanity checks)

curl https://hub.oxen.ai/api/chat/completions \
  -H "Authorization: Bearer $OXEN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o-mini",
    "messages": [
      {"role": "user", "content": "What is Oxen.ai in 2 sentences?"}
    ]
  }'

If this works, your SDK should work too.

3. Choose a model from Oxen.ai

You have three main categories to choose from:

  1. Foundation models – e.g., gpt-4o-mini, llama-3.1-8b-instruct, llama-3.1-70b-instruct.
  2. Specialized models – embeddings, vision, and audio models with specific pricing per token/image/second.
  3. Your fine-tuned / custom models – models you train inside Oxen, based on your versioned datasets, then deploy as serverless endpoints.

You specify them exactly like OpenAI models:

response = client.chat.completions.create(
    model="llama-3.1-70b-instruct",
    messages=[{"role": "user", "content": "Draft a product spec checklist."}]
)

Or, with a fine-tuned model:

response = client.chat.completions.create(
    model="ft:my-team/spec-bot-2025-03-10",  # example Oxen fine-tuned ID
    messages=[{"role": "user", "content": "Review this spec for missing edge cases."}]
)

Oxen’s UI will show you the exact model identifier or endpoint name to use.

4. Use other familiar endpoints (embeddings, images, etc.)

If your app calls other OpenAI endpoints, you can keep the same pattern:

Embeddings:

embedding = client.embeddings.create(
    model="text-embedding-3-small",
    input="Version every asset, including model weights and datasets."
)
vector = embedding.data[0].embedding

Images (if supported in your Oxen catalog):

image = client.images.generate(
    model="flux-dev",  # example image model
    prompt="A data engineer debugging a massive dataset sync to S3."
)

The exact model names and availability live in the Oxen model catalog; pricing is listed per token/image/second with no hidden subscription.

Common Mistakes to Avoid

  • Forgetting to change the base URL:
    Many teams swap the key and model but leave api.openai.com in place. Always set base_url/baseURL/base_uri to https://hub.oxen.ai/api.

  • Using a model name not available on Oxen:
    If you copy an OpenAI-only model name, you’ll get errors. Check Oxen’s model list or your fine-tuned model page and copy the exact identifier.

  • Hard-coding secrets in code:
    API keys in source control create a bad day. Use environment variables, secret managers, or your existing config system.

  • Ignoring pricing differences:
    Model pricing and limits can differ from OpenAI. Check Oxen’s pricing for the model you choose so you’re not surprised by token or image volume costs.

Real-World Example

Imagine you already have a product prototype using OpenAI’s gpt-4o-mini for support summarization, wired up in a backend service. Your blockers are:

  • You need to fine-tune on your own support dataset.
  • You want reproducibility: “which data trained which model?” needs a clear answer.
  • You’d like pay-as-you-go serverless inference without owning infrastructure.

With Oxen.ai, you:

  1. Upload and version your support transcripts as a dataset in an Oxen repository.
  2. Fine-tune a custom support summarization model in a few clicks—no infra, no custom training loop.
  3. Deploy the fine-tuned model to a serverless endpoint.
  4. Update your existing service by:
    • Changing base_url to https://hub.oxen.ai/api.
    • Swapping the API key to your Oxen token.
    • Replacing model="gpt-4o-mini" with your fine-tuned model ID (e.g., ft:acme/support-summarizer-v1).

Your backend code hardly changes, but now your app is powered by a custom, reproducible model tied to a versioned dataset. When product asks, “What changed between v1 and v2?” you can point directly to the dataset diff and fine-tune run.

Pro Tip: When you deploy a fine-tuned model on Oxen, save the model ID and the exact dataset commit hash together in your app config or release notes. That gives you a clean audit trail from production behavior back to the training data.

Summary

To point your existing OpenAI SDK to Oxen.ai’s OpenAI-compatible API (https://hub.oxen.ai/api), you don’t need to rewrite your app. Generate an Oxen API key, change the SDK’s base URL, plug in the new key, and select an Oxen-supported model (or your own fine-tuned endpoint) via the model field. From there, you can keep your existing request patterns—chat completions, embeddings, images—while owning your data, your models, and the full dataset → fine-tune → deploy loop.

Next Step

Get Started