Skip to content

Quickstart

From zero to your first answer in minutes — over plain HTTP. No SDK to install: works from any language with curl, Python, JavaScript, Go and beyond.

1 · Get a project key

Every request authenticates with a project key in the Authorization header. Get one by signing in at the console: Google/GitHub gives you a project key + $2 free credit (email sign-in starts at $0). Copy the key and export it once. When the wallet runs out you get a 402 INSUFFICIENT_CREDIT — POST /v1/account/topup and open the returned checkout_url to add funds:

bash
# Get a project key: sign in with Google/GitHub at the console for your
# project key + $2 free credit (email sign-in starts at $0). Copy the key,
# then export it once:
export INFRAI_API_KEY="ifr_pk_proj_..."

# When the wallet runs out you get 402 INSUFFICIENT_CREDIT — top up and open
# the returned checkout_url to add funds:
curl -X POST https://api.infrai.cc/v1/account/topup \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"amount": 20, "currency": "USD", "payment_method": "stripe"}'

2 · AI inference — point the OpenAI SDK at infrai

AI inference is OpenAI-API-compatible: you already know the API. Just change the base URL to https://api.infrai.cc/v1 and use chat/completions, embeddings, images/generations, audio/speech, audio/transcriptions, moderations and models exactly as you know them. No new SDK, no new knowledge.

python
from openai import OpenAI

client = OpenAI(base_url="https://api.infrai.cc/v1", api_key=INFRAI_API_KEY)
resp = client.chat.completions.create(
    model="auto",  # infrai picks the best/cheapest live vendor; or pin "gpt-4o-mini"
    messages=[{"role": "user", "content": "Summarize the latest news"}],
)
print(resp.choices[0].message.content)
print(resp.infrai["cost_usd"], resp.infrai["vendor"])  # infrai cost/vendor extension

Smart routing rides the model field: model="auto" lets infrai pick the best/cheapest live vendor (pass task/prefer via extra_body), or pin a real model like "gpt-4o-mini" / "deepseek-chat". Cost and vendor come back in an extra top-level infrai object plus X-Infrai-* headers — an OpenAI client ignores the extra field. (The old custom /v1/ai/chat shapes are retired.)

3 · Any other capability

Everything non-AI is a plain HTTP call to https://api.infrai.cc/v1/... — POST JSON with a Bearer key. China-region vendors bill at 0% markup, Western at 5%. Send an email, schedule a job, store a file — same key, same envelope, just a different path. For example, send an email:

bash
curl -X POST https://api.infrai.cc/v1/email/send \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"to": "alice@example.com", "subject": "Welcome", "html": "<p>Hi!</p>"}'

Response

json
{
  "ok": true,
  "data": { /* capability-specific result */ },
  "error": null,
  "metadata": {
    "cost_usd": 0.00012,
    "latency_ms": 412,
    "vendor": "deepseek",
    "cache_hit": false,
    "request_id": "01HXY..."   // UUID v7
  }
}

Every call returns the same envelope: `data` is the capability result, `error` is null on success, and `metadata` carries cost, vendor, latency and the request id. See Conventions for the full spec.

Any language

It is just HTTP, so any language with an HTTP client works — Go, Rust, Java, C#/.NET, Ruby, PHP and more. Every response returns the same { ok, data, error, metadata } envelope with cost, latency and vendor metadata.

Next steps