halfoff.devDocs
Get a key
Integrations

SDKs

Use the official OpenAI, Anthropic and Google Gen AI SDKs with Half Off Dev at half the official price by setting two client options.

Because Half Off Dev speaks each vendor's API in its own format, you don't need a special client library. Install the official SDK, give the client constructor Half Off Dev's base URL and your key, and follow the vendor's documentation for everything after that. Create an API key first.

Tip

Under Use in tools on API keys, the cURL / SDK tab has these samples with your key already inserted.

Anthropic SDK#

Base URL https://halfoff.dev, without /v1: the SDK adds the version itself.

import os
import anthropic

client = anthropic.Anthropic(
    base_url="https://halfoff.dev",
    api_key=os.environ["HALFOFF_API_KEY"],
)
message = client.messages.create(
    model="claude-sonnet-5.5",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Suggest a name for a CLI that renames files."}],
)
print(message.content[0].text)

OpenAI SDK#

Base URL https://halfoff.dev/v1.

import os
from openai import OpenAI

client = OpenAI(
    base_url="https://halfoff.dev/v1",
    api_key=os.environ["HALFOFF_API_KEY"],
)
completion = client.chat.completions.create(
    model="gpt-6.1-sol",
    messages=[{"role": "user", "content": "Write a regex that matches ISO dates."}],
)
print(completion.choices[0].message.content)

Chat Completions accepts every text model, so this one client can also call claude-sonnet-5.5 or gemini-3.1-pro by changing model.

Google Gen AI SDK#

Base URL https://halfoff.dev, passed through the HTTP options.

import os
from google import genai
from google.genai import types

client = genai.Client(
    api_key=os.environ["HALFOFF_API_KEY"],
    http_options=types.HttpOptions(base_url="https://halfoff.dev"),
)
response = client.models.generate_content(
    model="gemini-3.1-pro",
    contents="Summarise the CAP theorem in one paragraph.",
)
print(response.text)

Format-specific details: Anthropic Messages, OpenAI Chat Completions, Gemini.

Fixing errors#

What you seeWhat to do
401 Missing API keyThe client sent no key. Check that HALFOFF_API_KEY is set where your code runs.
401 Invalid or revoked API keyThe key was mistyped, cut short or revoked. Paste it again or make a new one.
404 Model '...' is not availableThat id doesn't exist. Copy one from GET /v1/models or the model list.
404 with /v1/v1/ in the pathYou gave the Anthropic SDK https://halfoff.dev/v1. It adds /v1 itself, so pass https://halfoff.dev; only the OpenAI SDK takes the /v1 form.
402The balance is empty or the key has hit its spend cap. See Billing.

Any other status is explained in Errors.