Inference APIs

Use Inference APIs with OpenAI Python SDK

Point the official openai Python package at Inference APIs with base_url. Chat, streaming, tool calling, speech and transcription all work unchanged.

Settings

SettingValue
Base URLhttps://api.inferenceapis.com/v1 (also /openai/v1)
API keyFrom API Keys; send as Authorization: Bearer …
Chat model idsopenai/gpt-oss-120b, deepseek-ai/DeepSeek-V4-Flash, zai-org/GLM-5.3-Flash, meta-llama/Llama-3.3-70B-Instruct-Turboall models
Audio model idsopenai/whisper-large-v3 (transcription), hexgrad/Kokoro-82M (speech)

Configuration

Install
pip install openai
Chat
import os
from openai import OpenAI

client = OpenAI(base_url="https://api.inferenceapis.com/v1", api_key=os.environ["INFERENCE_API_KEY"])

resp = client.chat.completions.create(
    model="openai/gpt-oss-120b",
    messages=[{"role": "user", "content": "Hello"}],
    max_tokens=400,
)
print(resp.choices[0].message.content)
Streaming
with client.chat.completions.stream(model="deepseek-ai/DeepSeek-V4-Flash", messages=[{"role": "user", "content": "Write a haiku"}]) as s:
    for event in s:
        if event.type == "content.delta":
            print(event.delta, end="", flush=True)
Speech and transcription
audio = client.audio.speech.create(model="hexgrad/Kokoro-82M", voice="af_heart", input="Hello there")
audio.write_to_file("hello.mp3")

with open("hello.mp3", "rb") as f:
    text = client.audio.transcriptions.create(model="openai/whisper-large-v3", file=f).text
print(text)
Environment variables instead of code
export OPENAI_BASE_URL="https://api.inferenceapis.com/v1"
export OPENAI_API_KEY="$INFERENCE_API_KEY"   # then OpenAI() with no arguments

Verify

Smoke test
python -c "from openai import OpenAI; import os; print([m.id for m in OpenAI(base_url='https://api.inferenceapis.com/v1', api_key=os.environ['INFERENCE_API_KEY']).models.list().data][:5])"

Gotchas

  • Reasoning models (GPT-OSS, DeepSeek, GLM) need max_tokens of a few hundred or more; the reply is empty when the budget is spent on reasoning.
  • client.responses (the Responses API) is not supported; use chat.completions.

If something fails

401 — key missing or wrong · 402 insufficient_balance — add credits on Billing · 404 model_not_found — check the id against the model list (aliases such as gpt-oss-120b work too) · 503 model_unavailable — the model is being enabled. Full details in the API docs.