OpenAI Protocol: chat/completions in Depth

Call all 175 models through the OpenAI-compatible endpoint — streaming, tool calling, multimodal image input, structured JSON output and embeddings, with copy-paste examples.

Endpoint: https://api.zaimod.com/v1/chat/completions. Any OpenAI SDK (Python / Node / Go / Rust / Java) or community SDK that supports a custom base_url works.

Basic chat

Python
resp = client.chat.completions.create(
    model="gpt-4.1",
    messages=[
        {"role": "system", "content": "You are a precise technical translator."},
        {"role": "user", "content": "Translate this to English: ..."},
    ],
    temperature=0.2,
    max_tokens=2000,
)

Streaming

Python
stream = client.chat.completions.create(
    model="gemini-3-pro-preview",
    messages=[{"role": "user", "content": "Write a haiku about databases"}],
    stream=True,
)
for chunk in stream:
    delta = chunk.choices[0].delta.content
    if delta:
        print(delta, end="", flush=True)

In Node.js, iterate with for await (const chunk of stream).

Tool calling (function calling)

Python
tools = [{
    "type": "function",
    "function": {
        "name": "get_weather",
        "description": "Look up city weather",
        "parameters": {
            "type": "object",
            "properties": {"city": {"type": "string"}},
            "required": ["city"],
        },
    },
}]

resp = client.chat.completions.create(
    model="gpt-5.6-terra",
    messages=[{"role": "user", "content": "What's the weather in Shanghai?"}],
    tools=tools,
)

call = resp.choices[0].message.tool_calls[0]
print(call.function.name, call.function.arguments)
# Run the function and pass the result back as the next message

Tool calling works on GPT, Claude, Gemini and DeepSeek lines. Parallel calls and strict mode differ per vendor — validate complex tool chains on a small traffic slice first.

Multimodal: image input

Python
resp = client.chat.completions.create(
    model="gpt-5.6-terra",
    messages=[{
        "role": "user",
        "content": [
            {"type": "text", "text": "What's wrong in this screenshot?"},
            {"type": "image_url", "image_url": {"url": "https://example.com/shot.png"}},
        ],
    }],
)

Image URLs and base64 data URLs are both supported.

Structured JSON output

Python
resp = client.chat.completions.create(
    model="gpt-4.1",
    messages=[{"role": "user", "content": "Extract company names and amounts as JSON"}],
    response_format={"type": "json_object"},
)

Pair it with field descriptions in the prompt for reliability.

Embeddings

Python
resp = client.embeddings.create(
    model="text-embedding-3-small",
    input=["first document", "second document"],
)
print(len(resp.data[0].embedding))  # 1536

Error handling pattern

Python
import time
from openai import APIStatusError, RateLimitError

for attempt in range(4):
    try:
        resp = client.chat.completions.create(...)
        break
    except RateLimitError:
        time.sleep(2 ** attempt)      # 429: exponential backoff
    except APIStatusError as e:
        if e.status_code >= 500:
            time.sleep(2 ** attempt)  # 5xx: retry, channel may rotate
        else:
            raise

Full error table: billing and error codes.

← Quickstart: Your First Request in 5 Minutes Claude-Native Endpoint: /v1/messages →