Disclosure: I work on APIrove, the API platform used in the examples below. The patterns themselves (custom
base_url, separate endpoints per output type, async video jobs) apply to most OpenAI-compatible providers, so I've tried to keep this useful even if you never use it.
Most AI side projects start the same way: one SDK, one vendor, one key. Then a feature needs an image model, someone wants to try a different text model, and a video experiment shows up. Suddenly you have three clients, three auth styles and three billing dashboards.
One way to keep this manageable is to keep the OpenAI SDK you already use and change only the base_url. This post walks through doing that against one base URL that serves text, image and video models, and calls out the places where "OpenAI-compatible" still needs a careful look.
Step 1: Keep the key out of your code
Before touching the client, put the key and model ID in environment variables. The key should only live on your server, never in browser JavaScript, a mobile app bundle or a public repo.
export APIROVE_API_KEY='YOUR_API_KEY' export APIROVE_MODEL='YOUR_MODEL_ID' Step 2: Change one line in the client
With the official Python SDK (pip install openai), the only change is the base_url. Note that it ends at /v1; the SDK appends the endpoint path itself.
import os from openai import OpenAI client = OpenAI( api_key=os.environ["APIROVE_API_KEY"], base_url="https://apirove.com/v1", ) response = client.responses.create( model=os.environ["APIROVE_MODEL"], input="Hello!", max_output_tokens=16, ) print(response.output_text) The max_output_tokens=16 is deliberate. For a first request you want the smallest possible call that proves auth, model access and billing all work.
Step 3: Know which endpoint each model speaks
This is the part where "compatible" can bite you. A single base URL does not mean every model accepts every request shape. On APIrove, as documented:
- GPT text models:
/v1/responsesand/v1/chat/completions - Grok text models:
/v1/chat/completions - Claude models:
/v1/messages(the Anthropic-style endpoint that Claude Code expects) - Image models:
/v1/images/generations - Video models:
/v1/videos, asynchronous
So if your app is built on the Responses API and you want to try a Grok model, switch that call to Chat Completions:
chat = client.chat.completions.create( model="grok-4.7", messages=[{"role": "user", "content": "Summarize this changelog in one line."}], max_tokens=64, ) print(chat.choices[0].message.content) Same client, same key, different endpoint. Check the model's page for its supported endpoint before wiring it in. That's cheaper than debugging a 403.
Step 4: Images through the same client
Image generation uses the standard Images API call:
image = client.images.generate( model="gpt-image-2", prompt="A red ceramic cup on a pale desk, soft daylight, uncluttered composition", size="1024x1024", n=1, ) One detail worth knowing: if you omit model on an image request, a default model is selected (currently gpt-image-2.6-flare). If you want reproducible output from a script, always set the model ID explicitly.
Step 5: Video is a job, not a request
Video generation is where most integrations need real changes, because it is asynchronous. The flow is create, poll, download:
# 1. Create a task curl https://apirove.com/v1/videos \ -H "Authorization: Bearer $APIROVE_API_KEY" \ -H "Content-Type: application/json" \ -d '{"model": "grok-imagine-video", "prompt": "A small sailboat crossing calm water at sunrise, steady wide shot", "seconds": "5", "resolution": "720p"}' # 2. Check status with the returned id curl https://apirove.com/v1/videos/$VIDEO_ID \ -H "Authorization: Bearer $APIROVE_API_KEY" # 3. Download the MP4 once status is "completed" curl -L https://apirove.com/v1/videos/$VIDEO_ID/content \ -H "Authorization: Bearer $APIROVE_API_KEY" \ -o video.mp4 From Python, the SDK has no dedicated helper for this endpoint, but the generic post method works:
task = client.post( "/videos", cast_to=object, body={ "model": "grok-imagine-video", "prompt": "A small sailboat crossing calm water at sunrise, steady wide shot", "seconds": "5", "resolution": "720p", }, ) print(task) # keep the returned id, then poll until completed The video models on sale (Seedance 2.0, Grok Imagine Video and Wan 3.0) all follow this same create/poll/download pattern, so once your job runner works for one, swapping models is mostly a matter of changing model, seconds and resolution to values that model's page lists.
A practical tip: store the task ID as soon as you get it. If your worker crashes mid-poll, you can resume polling instead of creating (and paying for) a second clip.
Step 6: Key groups and permissions
One thing that's easy to miss: keys come in two groups. A Text group key (the default for new keys) covers GPT text models and image generation. Claude and video need a Full group key. If a Claude or video call returns 403 with an otherwise valid key, check the key group first.
Step 7: Errors and retries
The docs list a short troubleshooting table that applies to most gateways:
- 401: wrong, revoked or malformed key. Check the
Authorization: Bearerheader for stray whitespace. - 403: account status, model access, or the model doesn't support that endpoint.
- 429: slow down and back off; don't hammer retries.
- 5xx: record the request ID if present, and confirm whether the original request completed (and was billed) before retrying.
That last point matters more than it looks. For streaming calls and video jobs, a disconnect doesn't necessarily mean the work wasn't done. Retrying blindly can mean paying twice.
Billing model, briefly
Since cost is usually the first question: usage is deducted from a prepaid balance at published per-model USD rates. Text is priced per 1M tokens (input and output separately, with cache rates on some models), images per image by size tier, and video per second by resolution. There's no subscription or monthly fee. The docs suggest sending one tiny request and reading the actual charge on the usage page before estimating anything at scale, which is good advice for any provider.
Wrapping up
The general recipe is: keep your SDK, change base_url, then check three things per model: which endpoint it speaks, whether your key has access, and whether the output is synchronous or a job. Get those right and adding a new model is a config change rather than a new integration.
The full endpoint reference, plus setup guides for Cursor, Claude Code, Codex, Cline and others, is in the APIrove API documentation. If you've hit other "compatible but not quite" edge cases with OpenAI-style gateways, I'd like to hear about them in the comments.