Cookbook

Copy. Run. Ship.

Streaming chat

Token-by-token SSE with the OpenAI SDK.

from openai import OpenAI
client = OpenAI(api_key="$RUNAII_API_KEY",
                base_url="https://api.runaii.cloud/v1")
for chunk in client.chat.completions.create(
    model="runaii/glm-5.3-flash",
    messages=[{"role": "user", "content": "Hello!"}],
    stream=True):
    print(chunk.choices[0].delta.content or "", end="")

Function calling

Tools schema works on every fn-calling model.

resp = client.chat.completions.create(
    model="runaii/kimi-k3",
    messages=[{"role": "user", "content": "What GPUs are cheapest?"}],
    tools=[{"type": "function",
            "function": {"name": "get_pricing",
                         "parameters": {"type": "object",
                                        "properties": {}}}},
    tool_choice="auto")

RAG: embed + rerank

Qwen3 embeddings, cross-encoder rerank.

emb = client.embeddings.create(
    model="runaii/qwen3-embedding-8b",
    input=["runaii pricing", "modal cold starts"])
# POST /v1/rerank {model, query, documents}
# → top-k passages for your prompt

Batch at 50% off

Async jobs for evals and backfills.

# console → Batch API → submit job
# same gateway, half the per-token rate,
# results ready for download on completion

Spend guardrails

Never wake up to a surprise bill.

# console → Settings
# hard spend limit ($) → over-limit calls get 402
# low-credit alerts via email + webhook (credit.low)

Verify webhooks

HMAC-SHA256 over the raw body.

import hmac
sig = hmac.new(WHSEC.encode(), raw_body, "sha256").hexdigest()
assert hmac.compare_digest("sha256=" + sig,
                           headers["X-Runaii-Signature"])