halfoff.dev
Get a key
Guide

Use the OpenAI SDK with Claude and Gemini

Change base_url and the API key to call Claude, GPT and Gemini from one OpenAI client in Python or Node.js, and learn where that shortcut stops working.

Prepaid, no subscriptionREST or MCPOne key for models, data and agents

The OpenAI SDK is the most widely supported client in the ecosystem, and it lets you change two things: the base URL and the API key. Point them at Half Off Dev and the same client can call GPT, Claude and Gemini models, so switching a model is a one-word change. This page shows the setup in Python and Node.js, how to list models, and, importantly, what you give up compared with each vendor's own API.

01

The two-line change

from openai import OpenAI

client = OpenAI(base_url="https://halfoff.dev/v1", api_key="ho-...")

reply = client.chat.completions.create(
    model="claude-sonnet-5.5",
    messages=[{"role": "user", "content": "Say hello in French."}],
)
print(reply.choices[0].message.content)

Keep /v1 on the base URL here: the OpenAI SDK adds only the path after it. Environment variables work too: OPENAI_BASE_URL and OPENAI_API_KEY are read by the official SDKs, so existing code and tools can be redirected without editing it.

02

List the models

Python
for m in client.models.list():
    print(m.id)

GET https://halfoff.dev/v1/models is public and returns every model with its price. Use those ids exactly; the model list shows them too.

03

Where the shortcut stops

Chat Completions is OpenAI's format. When you send it to a Claude or Gemini model, the request is converted for that model, so features that exist only in the vendor's own API may be dropped or refused. In practice:

You wantUse
Plain chat, streaming, function calling, JSON outputThe OpenAI client works with every model
Claude cache_control, extended thinkingThe Anthropic SDK against https://halfoff.dev (guide)
Gemini thinkingConfig, native audio and video inputThe Gemini SDK or REST (guide)
GPT Responses API, Codex CLIhttps://halfoff.dev/v1/responses (guide)

If a price matters, the native format also matters: Claude's cache discount needs cache_control, which is only guaranteed in Anthropic format. Prompt caching explains each vendor's way.

04

Troubleshooting

{}
401

the key isn't reaching the server, or it was mistyped. Check the environment variable name your code reads.

404 mentioning the model

the id isn't in GET /v1/models. Copy it from there.

404 with /v1/v1/ in the path

the base URL ends in /v1 and the tool adds it again. Remove it for tools that append /v1 themselves.

402

the balance is empty or a spend cap was hit. See Billing.

The full list is in Errors.

05

Frequently asked questions

?
Can I use the OpenAI SDK with Claude?+

Yes. Set the base URL to https://halfoff.dev/v1, use your key, and set model to a Claude id such as claude-sonnet-5.5. For Claude-only features like prompt caching controls, use the Anthropic SDK instead.

Does the OpenAI Python library support a custom base URL?+

Yes: pass base_url to the client, or set OPENAI_BASE_URL. The same goes for the Node.js library with baseURL.

Is it OpenAI-compatible, or the real API?+

Both formats are served natively on the same host: OpenAI Chat Completions and Responses, Anthropic Messages and Gemini. Pick the one your code already speaks.

Which model should I start with?+

A mid-sized model from any vendor; compare with the calculator and the vendor price guides for Claude, GPT and Gemini.

How much does it cost?+

Every model is half of its official list price, billed per token from a prepaid balance. Create an account and make a key to start.

One prepaid key for models, data and agents

No subscription. Top up, use what you need, see every charge in your logs.