Docs · harness integration

Your key drops into the harness you already run.

3z-Intelligence speaks the OpenAI chat-completions dialect. Hermes, a CLI coding agent, an editor agent or your own framework: anything that takes a base URL and an API key runs on our models with three values and no new SDK, once the public API door opens. It is not open yet; the values below are ready for that day.

The three values

Base URL

https://api.3z-intelligence.example/v1

Not open yet: the public API door (/v1) has not shipped, so this host is a placeholder. The production host replaces it here and in your dashboard when the door opens.

API key

Minted in your account dashboard and shown once. Keep it in an environment variable: THREEZ_API_KEY on this page.

A key calls models. It cannot buy top-ups or change your plan.

Model

qwen38-flash-next for the agent loop.

qwen38-27b-mtp for review and second opinions.

Details in the model catalog below.

Hermes

Hermes reads named OpenAI-compatible providers from the providers: block of its config. Add one entry, keep the key in Hermes's env file, and point the model at the entry.

# ~/.hermes/config.yaml
providers:
  threez:
    api: https://api.3z-intelligence.example/v1
    key_env: THREEZ_API_KEY        # read from ~/.hermes/.env, never written here
    default_model: qwen38-flash-next
    models:
      qwen38-flash-next:
        context_length: 262144
      qwen38-27b-mtp:
        context_length: 262144

model:
  provider: custom:threez
  default: qwen38-flash-next
# ~/.hermes/.env
THREEZ_API_KEY=<paste the key you minted>

One question proves the base URL, the key and the model together:

hermes chat --oneshot -q "Reply with the word ready."

Inside a session, hand the next turn to the reviewer model with /model custom:threez:qwen38-27b-mtp, and switch back the same way.

Any OpenAI-compatible harness

Most tools that speak the OpenAI API read two environment variables. Set them where the harness starts, and the tool, its SDK and its sub-agents all inherit them.

# the harness's env file, launcher or CI secret store
export THREEZ_API_KEY="<paste the key you minted>"
export OPENAI_BASE_URL="https://api.3z-intelligence.example/v1"
export OPENAI_API_KEY="$THREEZ_API_KEY"

Exported in your login shell, these two variables redirect every OpenAI-SDK tool you start from it. Scope them to the harness when you also call other providers.

curl

# which models can this key call?
curl -sS https://api.3z-intelligence.example/v1/models \
  -H "Authorization: Bearer $OPENAI_API_KEY"

# one chat completion
curl -sS https://api.3z-intelligence.example/v1/chat/completions \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"qwen38-flash-next","messages":[{"role":"user","content":"gm"}]}'

# streamed as server-sent events, the way most agent loops read it
curl -sS -N https://api.3z-intelligence.example/v1/chat/completions \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"qwen38-flash-next","stream":true,"messages":[{"role":"user","content":"gm"}]}'

Python, with the official openai client

# pip install openai   (nothing 3z-specific to install)
import os
from openai import OpenAI

client = OpenAI(
    base_url=os.environ["OPENAI_BASE_URL"],  # https://api.3z-intelligence.example/v1
    api_key=os.environ["OPENAI_API_KEY"],
)

resp = client.chat.completions.create(
    model="qwen38-flash-next",
    messages=[{"role": "user", "content": "gm"}],
)
print(resp.choices[0].message.content)

Called with no arguments, OpenAI() reads the same two variables. They're passed explicitly here so the wiring is visible.

Three harness shapes

Every harness exposes the same three settings under different names: where to send requests, which key to send and which model to ask for. The field names below are illustrative. Match them to your tool; the values don't change.

A CLI coding agent (TOML provider table)

# ~/.config/your-coding-agent/config.toml   (field names vary by tool)
[providers.threez]
name        = "3z-Intelligence"
base_url    = "https://api.3z-intelligence.example/v1"
api_key_env = "THREEZ_API_KEY"         # read from the environment, never stored here
api         = "openai-chat-completions"

[agent]
provider = "threez"
model    = "qwen38-flash-next"

An editor agent (JSON settings)

{
  "models": [
    {
      "title": "3z Flash Next",
      "provider": "openai-compatible",
      "baseUrl": "https://api.3z-intelligence.example/v1",
      "apiKeyEnv": "THREEZ_API_KEY",
      "model": "qwen38-flash-next",
      "contextLength": 262144
    },
    {
      "title": "3z 27B reviewer",
      "provider": "openai-compatible",
      "baseUrl": "https://api.3z-intelligence.example/v1",
      "apiKeyEnv": "THREEZ_API_KEY",
      "model": "qwen38-27b-mtp",
      "contextLength": 262144
    }
  ]
}

If the editor only takes a pasted key, put it in the editor's secret storage, not in a settings file that syncs or gets committed.

An agent framework client (Python)

# any agent framework that accepts an OpenAI-compatible client
import os
from openai import OpenAI
from your_framework import Agent  # placeholder for the framework you use

llm = OpenAI(base_url=os.environ["OPENAI_BASE_URL"], api_key=os.environ["OPENAI_API_KEY"])

builder = Agent(client=llm, model="qwen38-flash-next")  # fast main loop
reviewer = Agent(client=llm, model="qwen38-27b-mtp")    # second opinion on the result

Model catalog

Three models in the catalog, each with a 262,144-token window. Run the loop on qwen38-flash-next, hand finished work to qwen38-27b-mtp for review, and use inkling-2-mini for quick everyday calls; Flash Next and Inkling both take images. Your plan decides which of them your key may call (Free: Inkling; Builder: Flash Next and Inkling; Pro and Max: all three), and GET /v1/models returns exactly that list.

Machine-readable catalog, the same file this page and the home page render from:

models.json

Quota stops: what your harness sees

Published, not enforced yet. This section is the contract the API door will enforce when it ships. Today the gate stops a key at the monthly allowance with its own 429 (an over-budget error, not the body below), the weekly window is not enforced, and nothing bills past your plan. Treat any 429 as a stop, and wire your client for these bodies now, so it behaves when they arrive.

Capacity plans have two windows: a weekly allowance and a monthly cap. Under the contract, hitting either one returns HTTP 429 with a machine-readable body. Neither clears on retry. A person has to decide, or the window has to roll over. Every error on this API uses one envelope:

{"error": {"code": "…", "message": "…"}}

Weekly allowance reached: weekly_limit_reached

The week's allowance, plus any unexpired top-up tokens, is spent. A top-up pack restores service the moment it's bought; an upgrade raises both windows.

HTTP 429
{
  "error": {
    "code": "weekly_limit_reached",
    "message": "Weekly token limit reached. Buy a recharge pack to restore service immediately, or upgrade your plan."
  },
  "limit": {"window": "weekly", "used": 6000250, "allowance": 6000000},
  "recharge_options": [
    {"pack_id": "pack_s", "tokens": 5000000, "price_usd": "9", "discount_pct": 25.0},
    {"pack_id": "pack_m", "tokens": 15000000, "price_usd": "24", "discount_pct": 30.0},
    {"pack_id": "pack_l", "tokens": 40000000, "price_usd": "56", "discount_pct": 35.0}
  ],
  "upgrade_options": [
    {"plan_id": "capacity_m", "monthly_token_cap": 100000000, "price_usd": "199",
     "priority_routing": false, "notes": "hard stop"},
    {"plan_id": "capacity_l", "monthly_token_cap": 500000000, "price_usd": "749",
     "priority_routing": true, "notes": "hard stop + priority routing"}
  ]
}

Monthly cap reached: monthly_cap_reached

The plan's monthly cap is the contract's hard stop, and a bill never grows past the plan. Top-ups cannot lift it, which is why this body carries upgrade options only.

HTTP 429
{
  "error": {
    "code": "monthly_cap_reached",
    "message": "Monthly token cap reached. This is a hard stop; recharges do not lift it. Upgrade your plan or wait for the next period."
  },
  "limit": {"window": "monthly", "used": 20000000, "cap": 20000000},
  "upgrade_options": [
    {"plan_id": "capacity_m", "monthly_token_cap": 100000000, "price_usd": "199",
     "priority_routing": false, "notes": "hard stop"},
    {"plan_id": "capacity_l", "monthly_token_cap": 500000000, "price_usd": "749",
     "priority_routing": true, "notes": "hard stop + priority routing"}
  ]
}

Example account: Builder (plan id capacity_s). Prices are strings and come from the live plan table, so read them from the payload rather than hard-coding them. The weekly window trips once usage passes the allowance; the monthly window trips at the cap. priority_routing is a plan flag the payload carries; routing does not act on it yet.

What a harness should do

Most OpenAI SDKs retry 429s on their own; the official python client retries twice by default. Turn that off for this decision and route the quota codes yourself:

# quota-aware wrapper for a harness built on the official openai client
import os, random, time
from openai import OpenAI, RateLimitError, APIConnectionError, InternalServerError

client = OpenAI(
    base_url=os.environ["OPENAI_BASE_URL"],
    api_key=os.environ["OPENAI_API_KEY"],
    max_retries=0,  # the SDK would retry a quota stop twice; decide here instead
)

QUOTA_STOPS = {"weekly_limit_reached", "monthly_cap_reached"}


class QuotaStop(Exception):
    """The account, not the network, needs a decision. Show .payload to a person."""

    def __init__(self, code, payload):
        super().__init__(code)
        self.code = code
        self.payload = payload


def chat(messages, model="qwen38-flash-next", attempts=4):
    for attempt in range(attempts):
        try:
            return client.chat.completions.create(model=model, messages=messages)
        except RateLimitError as e:
            try:
                payload = e.response.json()  # the full body; e.body holds only "error"
            except ValueError:
                payload = {}
            code = (payload.get("error") or {}).get("code")
            if code in QUOTA_STOPS:
                raise QuotaStop(code, payload) from None
            try:
                wait = float(e.response.headers.get("retry-after", ""))
            except ValueError:
                wait = 2 ** attempt
        except (APIConnectionError, InternalServerError):
            wait = 2 ** attempt
        time.sleep(wait + random.random())
    raise RuntimeError(f"gave up after {attempts} attempts")
try:
    reply = chat([{"role": "user", "content": "gm"}])
except QuotaStop as stop:
    if stop.code == "weekly_limit_reached":
        offer = stop.payload["recharge_options"] + stop.payload["upgrade_options"]
    else:  # monthly_cap_reached: a top-up cannot lift the cap
        offer = stop.payload["upgrade_options"]
    show_to_person(stop.payload["error"]["message"], offer)  # your UI; never auto-buy

One edge to handle: the weekly window is checked before the monthly one. If both are spent you'll see weekly_limit_reached first, and the top-up purchase then answers HTTP 409 with the monthly_cap_reached body. Surface its upgrade_options instead.

Buying a top-up (account session, not the API key)

In the dashboard, Add top-up pack opens the same offer. Over the API, it takes the session token from login:

GET  /api/billing/recharge/options
  -> 200 {"packs": [{"pack_id": "pack_s", "tokens": 5000000, "price_usd": "9", "discount_pct": 25.0}, …]}

POST /api/billing/recharge   {"pack_id": "pack_m"}
  -> 200 {"recharge_id": "…", "tokens_added": 15000000, "expires_at": "…"}
  -> 409 the monthly_cap_reached body: top-ups never lift the monthly cap

Top-up tokens add to the current week's allowance, expire at the end of the billing period and stay inside the monthly cap.

Account API: referral code to first key

The dashboard runs on this API, and you can script it. It lives under /api on this site’s own host (shown below as the placeholder 3z-intelligence.example). Session tokens from login drive /api/*; API keys drive /v1, once the API door opens. Neither works in the other's place.

1. Sign up (referral code required)

curl -sS -X POST https://3z-intelligence.example/api/auth/signup \
  -H "Content-Type: application/json" \
  -d '{"email":"you@example.com","password":"choose-one-good","referral_code":"TZI-XXXXXX"}'
# 201 {"account_id": "…"} and a verification email
# 403 code unknown, inactive or spent  ·  409 email already registered

2. Verify the email, then log in

curl -sS -X POST https://3z-intelligence.example/api/auth/verify \
  -H "Content-Type: application/json" \
  -d '{"token":"TOKEN_FROM_EMAIL"}'

curl -sS -X POST https://3z-intelligence.example/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{"email":"you@example.com","password":"choose-one-good"}'
# 200 {"session_token": "…", "expires_at": "…"}
# 429 too_many_attempts after 5 failed tries in 15 minutes;
#     the body's retry_after_seconds says when to try again

export SESSION="paste-the-session_token"

3. Start the Free plan, or pick a paid one

Minting a key needs the Free plan or an active paid plan, so start one first. Free needs no card and never expires; its plan id is trial.

curl -sS -X POST https://3z-intelligence.example/api/billing/subscribe \
  -H "Authorization: Bearer $SESSION" \
  -H "Content-Type: application/json" \
  -d '{"plan":"trial"}'
# 200 {"subscription": {"plan": "trial", "status": "trialing",
#                       "period_end": "…", …},
#      "invoice_ref": null, "payment_pending": false}
# 409 trial_already_used once the account has had any plan
#     (one Free plan per account)

A paid plan (capacity_s, capacity_m or capacity_l) also answers 200, but with "payment_pending": true and an invoice_ref, unless the account is already active on that plan. The plan, and its key limit, apply only once that invoice is paid. Until then the account stays on the plan it had, if it had one, and an account with no plan mints nothing.

4. Mint a key for your harness

curl -sS -X POST https://3z-intelligence.example/api/keys \
  -H "Authorization: Bearer $SESSION" \
  -H "Content-Type: application/json" \
  -d '{"label":"hermes-laptop"}'
# 201 {"key_id": "…", "label": "hermes-laptop", "api_key": "…"}
#     api_key appears in this response only; no screen or API returns it again
# 403 subscription_required: neither the Free plan nor an active paid plan
# 409 key_limit_reached: the plan's live-key cap is reached; the body's
#     "limit" says {"max_keys": …, "live_keys": …}

Lose the value and you revoke that key and mint a new one: revoked keys do not count toward the plan’s live-key cap. Label keys by harness or machine; DELETE /api/keys/{key_id} revokes one and leaves the rest running.

5. Read usage

curl -sS "https://3z-intelligence.example/api/usage?days=30&window=weekly" \
  -H "Authorization: Bearer $SESSION"
# 200 {"days": [{"date", "tokens", "requests", "spend_usd"}, …],
#      "by_model": [{"model", "tokens", "requests", "spend_usd"}, …],
#      "week_used": …, "weekly_allowance": …, "recharge_tokens_remaining": …}
# 503 usage_unavailable while the usage meter is not running or has fallen
#     behind, or cannot count one of your keys yet

Counts only: tokens, requests and notional cost per day and per model. spend_usd is the gate’s notional accounting cost, not a charge. Requests made with your API keys, and their completions, never pass through the 3z service, so there is no prompt or completion text here to leak.

Operational notes

Open your dashboard