Skip to content

Models

Quickstart: your first API call

By the end of this page you will have a Grafilab API key, a model id, a JSON completion in your terminal, a streamed version of the same call, and the row in your usage dashboard that shows what it cost.

  • A Grafilab account with your country set in your profile — that is what gives the account a billing currency. See Create Your Account.
  • A non-zero credit balance, or free credits on the model you pick. See Credits & Billing.
  • curl, or Python 3.9+, or Node.js 18+.
  1. Create an API key.

    In the console open API and click Generate New Key. Type a name — quickstart will do — and press Enter. The API Key Created dialog shows the full key once: copy it, then click I’ve saved my key. Afterwards the table masks the key to its last four characters, with a Show Key toggle if you need to read it again.

    Put the key in an environment variable so it never lands in your code:

    Terminal window
    export GRAFILAB_API_KEY="sk-grafilab-..."
  2. Pick a model.

    The model catalog is live, so list it rather than copying ids from a page. Every entry’s id is the exact string to use in any tool or SDK.

    Terminal window
    curl https://llm.grafilab.ai/v1/models \
    -H "Authorization: Bearer $GRAFILAB_API_KEY" | jq -r '.data[].id'

    The same ids appear as cards in the Playground, with context size and prices.

  3. Send a chat completion.

    The base URL is https://llm.grafilab.ai/v1. Any OpenAI-compatible client works — you only change the base URL and the key.

    The examples on this page use grafilab/qwen3.6-flash, the sample model from the API reference. Replace it with any id returned by GET /v1/models.

    Terminal window
    curl https://llm.grafilab.ai/v1/chat/completions \
    -H "Authorization: Bearer $GRAFILAB_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
    "model": "grafilab/qwen3.6-flash",
    "messages": [{"role": "user", "content": "Say hello in five words."}]
    }'

    You get back a standard chat completion, abbreviated here:

    {
    "id": "chatcmpl-...",
    "object": "chat.completion",
    "model": "grafilab/qwen3.6-flash",
    "choices": [
    {
    "index": 0,
    "message": { "role": "assistant", "content": "Hello, good to meet you today." },
    "finish_reason": "stop"
    }
    ],
    "usage": { "prompt_tokens": 13, "completion_tokens": 8, "total_tokens": 21 }
    }
  4. Stream the same call.

    Set stream: true to receive server-sent events as the model writes. Add stream_options: {"include_usage": true} so the last data frame before the terminator carries the token counts — without it a streamed call reports no usage to your client.

    Terminal window
    curl -N https://llm.grafilab.ai/v1/chat/completions \
    -H "Authorization: Bearer $GRAFILAB_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
    "model": "grafilab/qwen3.6-flash",
    "messages": [{"role": "user", "content": "Say hello in five words."}],
    "stream": true,
    "stream_options": {"include_usage": true}
    }'

    The raw SSE stream ends with data: [DONE].

  5. See what it cost.

    Back on API, find your key’s row and click View Usage. The console opens Inference API Usage filtered to that key, because every request is attributed to the key that authenticated it. Read Total cost and the Token breakdown tiles — Input, Cached, Output — for the day you made the calls.

    The footnote on that page reads All dates in UTC · data may lag up to 30 min: the rollup that feeds these numbers re-aggregates today and yesterday every 30 minutes, so a call you just made may not appear yet.

You are done when all three are true:

  • The non-streamed call returned a non-empty choices[0].message.content.
  • The streamed call printed text incrementally and finished with a usage object.
  • Within about 30 minutes, Inference API Usage for that key shows a non-zero Total cost and a token breakdown for today.

Text calls are charged after delivery, once per call, so a call that failed before producing output costs nothing.

  • 401 invalid_api_key — the key is wrong, was rotated, or picked up a space or newline when you pasted it. Copy it again from API; if you no longer have the value, rotate the key and use the new one.
  • 404 model_not_found — the id is misspelled, the model is invite-only, or it has no price in your account currency. Re-run GET /v1/models and copy an id from that response verbatim.
  • 429 insufficient_quota — this is a balance problem, not a throughput limit. Top up on Billing.
  • 403 billing_currency_unset — your account has no billing currency yet. Set your country in your profile, then retry.
  • Connection refused or 404 on the URL itself — check the base URL. The OpenAI surface is https://llm.grafilab.ai/v1 and clients append /chat/completions; Anthropic clients take the bare origin https://llm.grafilab.ai and append /v1/messages themselves.