Answers you can trust, from Codeables
Every page on Codeables is structured and verified — built so people and the AI agents they rely on can trust it. Explore more from the source behind this answer.
Explore CodeablesHow do I migrate from OpenAI to Clarifai using OpenAI-compatible endpoints (what do I change in base_url/keys)?
Most OpenAI users assume “migration” means weeks of refactors, new SDKs, and breaking changes. With Clarifai’s OpenAI-compatible endpoints, it comes down to two things: swap your base_url, update the API key, and you’re already hitting Clarifai instead of OpenAI.
Quick Answer: To migrate from OpenAI to Clarifai, point your OpenAI client to Clarifai’s OpenAI-compatible gateway (
base_url="https://api.clarifai.com/v2/ext/openai/v1") and replace your OpenAI key with a Clarifai Personal Access Token (PAT). The rest of your OpenAI-style code (methods, payloads, message format) can stay the same.
The Quick Overview
- What It Is: A drop-in, OpenAI-compatible endpoint on Clarifai that lets you keep your existing OpenAI client and payload shape while routing traffic to Clarifai’s faster, lower-cost inference platform.
- Who It Is For: Teams already using the OpenAI SDKs (Python, Node, etc.) or OpenAI-style REST calls who want better latency, throughput, and cost without rewriting client code.
- Core Problem Solved: Eliminates migration friction. Instead of a full re-integration, you change
base_urland keys once, then immediately tap into Clarifai’s GPU-optimized inference and unified control plane.
How It Works
Clarifai exposes an OpenAI-compatible gateway that speaks the same language as your existing OpenAI client libraries. Under the hood, Clarifai’s Compute Orchestration and Armada inference stack handle the heavy lifting—GPU fractioning, batching, autoscaling, and routing to the model you choose.
At the application level, you still call:
client = OpenAI(...)
client.chat.completions.create(...)
The difference is:
- The endpoint: You point
base_urlto Clarifai’s OpenAI-compatible URL. - The credential: You pass a Clarifai PAT instead of an OpenAI key.
- The model identifier: You reference a Clarifai-hosted model URL (e.g., GPT-OSS-120B, DeepSeek, Kimi K2.5, or your own).
1. Swap the base_url to Clarifai
In OpenAI’s Python client, you configure the Clarifai gateway like this:
from openai import OpenAI
client = OpenAI(
base_url="https://api.clarifai.com/v2/ext/openai/v1",
api_key="YOUR_CLARIFAI_PAT",
)
That’s the critical step. Once the base_url is set to Clarifai’s OpenAI extension, the same client methods route to Clarifai instead of OpenAI.
2. Replace your OpenAI API key with a Clarifai PAT
Generate a Personal Access Token (PAT) in the Clarifai UI, then either:
export OPENAI_API_KEY="YOUR_CLARIFAI_PAT"
or pass it explicitly:
client = OpenAI(
base_url="https://api.clarifai.com/v2/ext/openai/v1",
api_key="YOUR_CLARIFAI_PAT",
)
Clarifai’s OpenAI-compatible endpoint treats this PAT as your auth token—no separate auth flow, no new headers.
3. Point to a Clarifai model URL
Instead of gpt-4o or gpt-3.5-turbo, you reference a Clarifai-hosted model via its full URL. For example, GPT-OSS-120B:
response = client.chat.completions.create(
model="https://clarifai.com/openai/chat-completion/models/gpt-oss-120b",
messages=[
{"role": "user", "content": "Explain GPU fractioning in simple terms."}
],
)
print(response.choices[0].message.content)
The request/response shape stays OpenAI-style: messages, role, content, choices, message.
Under load, Clarifai’s stack gives you:
- Ultra-low TTFA (time-to-first-answer) thanks to GPU-optimized runtimes.
- High tokens/sec throughput verified by Artificial Analysis benchmarks (e.g., 410 tokens/sec for hosted Kimi K2.5).
- Cost control via GPU sharing, autoscaling, and centralized Control Center visibility.
Features & Benefits Breakdown
| Core Feature | What It Does | Primary Benefit |
|---|---|---|
| OpenAI-compatible gateway | Accepts OpenAI-style requests using the OpenAI SDKs and REST conventions. | Migrate by changing base_url and key instead of rewriting code or swapping SDKs. |
| Clarifai PAT authentication | Uses a single Personal Access Token for the OpenAI gateway and Clarifai APIs. | Simplified auth and easy rotation; one token powers your LLM, RAG, and workflow stack. |
| Model URL routing | Lets you call Clarifai-hosted models via URL identifiers. | Run open, third-party, or custom models without changing your client library calls. |
| Compute Orchestration + Armada | Packs models, batches requests, and autoscale GPUs behind the gateway. | Faster TTFA, higher tokens/sec, and reduced GPU spend without touching your app code. |
| Unified Control Center | Centralizes cost, latency, and usage metrics across models and teams. | Prevents AI sprawl and duplicated spend while you scale beyond a single model or provider. |
| Run-anywhere options | The same OpenAI-compatible gateway can back SaaS, VPC, on‑prem, air‑gapped. | Keep the simple OpenAI interface while meeting strict network and compliance requirements. |
Ideal Use Cases
- Best for high-traffic chat or agentic workloads: Because you can redirect existing OpenAI-based agents to Clarifai with a
base_urlchange and immediately benefit from lower latency and higher throughput under concurrency. - Best for enterprises consolidating AI spend: Because multiple teams can standardize on the OpenAI request format, route everything through Clarifai’s control plane, and avoid duplicated GPU contracts and unmanaged endpoints.
Step-by-Step Migration: Code Examples
Below are concrete examples showing exactly what changes in your client code.
Python: From OpenAI to Clarifai
Before (OpenAI):
from openai import OpenAI
client = OpenAI(
api_key="OPENAI_KEY",
)
resp = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "user", "content": "Summarize this text."}
],
)
print(resp.choices[0].message.content)
After (Clarifai OpenAI-compatible):
from openai import OpenAI
client = OpenAI(
base_url="https://api.clarifai.com/v2/ext/openai/v1", # CHANGED
api_key="YOUR_CLARIFAI_PAT", # CHANGED
)
resp = client.chat.completions.create(
model="https://clarifai.com/openai/chat-completion/models/gpt-oss-120b", # CHANGED
messages=[
{"role": "user", "content": "Summarize this text."}
],
)
print(resp.choices[0].message.content)
No method renames. No payload changes. You simply:
- Set
base_url - Swap
api_key - Point the
modelfield at a Clarifai model URL
Node.js: Using Clarifai Node SDK vs OpenAI client
You can either keep the OpenAI client with a base_url change (same pattern as Python), or use Clarifai’s native SDK.
Using Clarifai Node SDK with a Clarifai model URL:
import { Model } from "clarifai-nodejs";
const modelUrl =
"https://clarifai.com/openai/chat-completion/models/gpt-oss-120b";
async function run() {
const model = new Model({ url: modelUrl, pat: process.env.CLARIFAI_PAT });
const response = await model.predict({
inputs: [
{
data: {
text: { raw: "Give me three bullet points on GPU autoscaling." },
},
},
],
});
console.log(JSON.stringify(response, null, 2));
}
run().catch(console.error);
For a pure "no SDK change" approach, you can follow the same base_url pattern using OpenAI’s Node client, just like in Python.
Limitations & Considerations
-
Model naming differences:
Instead of short names likegpt-4o, you’ll typically use full Clarifai model URLs (e.g.,https://clarifai.com/openai/chat-completion/models/gpt-oss-120b).
Workaround: Wrap these in your own config constants or env vars to make swapping models trivial. -
Feature parity nuances:
Core chat/completions flows are OpenAI-compatible, but provider-specific features (e.g., certain OpenAI beta APIs or proprietary tools) may not have a 1:1 equivalent.
Workaround: Start with your mainchat.completions/completionspaths first. For advanced features, check Clarifai docs or consider implementing via Clarifai Mesh workflows and tools instead.
Pricing & Plans
Clarifai is built to be blisteringly fast and budget-friendly, with performance verified by third-party benchmarks like Artificial Analysis (e.g., “#1 fastest provider” for Kimi K2.5, 410 tokens/sec, sub-millisecond TTFA).
You can start on usage-based pricing, then graduate to enterprise agreements as you scale:
- Free / Developer Tier: Best for individual developers or small teams needing a quick path to experiment with OpenAI-compatible endpoints, validate latency, and run early prototypes with no credit card required.
- Enterprise Plans: Best for organizations needing production SLAs (99.99%+), private deployments (VPC, on‑prem, air‑gapped), RBAC/Teams, and unified cost/governance across multiple models and workloads.
For exact per‑token or per‑request pricing by model, see Clarifai’s pricing page or contact sales from your Clarifai account.
Frequently Asked Questions
What exactly do I change in base_url and keys to migrate from OpenAI?
Short Answer: Set base_url to https://api.clarifai.com/v2/ext/openai/v1 and replace your OpenAI key with a Clarifai PAT.
Details:
With the OpenAI Python client, the minimal change is:
from openai import OpenAI
client = OpenAI(
base_url="https://api.clarifai.com/v2/ext/openai/v1",
api_key="YOUR_CLARIFAI_PAT",
)
If you’re relying on OPENAI_API_KEY from the environment, you can simply store your Clarifai PAT in that variable:
export OPENAI_API_KEY="YOUR_CLARIFAI_PAT"
Then update your app’s config to use the Clarifai base_url. Your method calls like client.chat.completions.create remain exactly the same; you just point them at Clarifai’s OpenAI-compatible gateway.
Do I have to change my request payloads or response parsing logic?
Short Answer: No, the payload and response shape remain OpenAI-style for chat/completions.
Details:
Clarifai’s OpenAI-compatible endpoint is designed so that:
- You keep the same request body format (
messages,role,content, etc.). - You parse responses the same way (
response.choices[0].message.content). - You use the same method signatures (
chat.completions.create, etc.).
The only structural change you’ll typically make is the model identifier. You’ll move from an OpenAI short ID to a Clarifai model URL. If you already abstract your model name behind a config variable, the migration is mostly a config update plus a base_url swap.
Summary
Migrating from OpenAI to Clarifai using OpenAI-compatible endpoints is intentionally boring—in a good way. You don’t swap SDKs. You don’t rebuild payloads. You don’t rewrite your agents.
You:
- Set
base_url="https://api.clarifai.com/v2/ext/openai/v1". - Use a Clarifai Personal Access Token as your
api_key. - Point the
modelfield to a Clarifai-hosted model URL.
Behind that simple change, Clarifai’s Compute Orchestration and Armada give you faster TTFA, higher tokens/sec, and better GPU utilization, all governed through a single Control Center that prevents AI sprawl. You keep the OpenAI ergonomics and get production-grade performance and FinOps control.