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.
Prerequisites
Section titled “Prerequisites”- 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+.
Your first call
Section titled “Your first call”-
Create an API key.
In the console open API and click Generate New Key. Type a name —
quickstartwill 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-..."Terminal window $env:GRAFILAB_API_KEY = "sk-grafilab-..." -
Pick a model.
The model catalog is live, so list it rather than copying ids from a page. Every entry’s
idis 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'from openai import OpenAIclient = OpenAI(api_key="sk-grafilab-...", base_url="https://llm.grafilab.ai/v1")for model in client.models.list():print(model.id)import OpenAI from "openai";const client = new OpenAI({ apiKey: "sk-grafilab-...", baseURL: "https://llm.grafilab.ai/v1" });for await (const model of client.models.list()) {console.log(model.id);}The same ids appear as cards in the Playground, with context size and prices.
-
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 anyidreturned byGET /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."}]}'Terminal window pip install openaiimport osfrom openai import OpenAIclient = OpenAI(api_key=os.environ["GRAFILAB_API_KEY"],base_url="https://llm.grafilab.ai/v1",)response = client.chat.completions.create(model="grafilab/qwen3.6-flash",messages=[{"role": "user", "content": "Say hello in five words."}],)print(response.choices[0].message.content)Terminal window npm install openaiimport OpenAI from "openai";const client = new OpenAI({apiKey: process.env.GRAFILAB_API_KEY,baseURL: "https://llm.grafilab.ai/v1",});const response = await client.chat.completions.create({model: "grafilab/qwen3.6-flash",messages: [{ role: "user", content: "Say hello in five words." }],});console.log(response.choices[0].message.content);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 }} -
Stream the same call.
Set
stream: trueto receive server-sent events as the model writes. Addstream_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}}'stream = client.chat.completions.create(model="grafilab/qwen3.6-flash",messages=[{"role": "user", "content": "Say hello in five words."}],stream=True,stream_options={"include_usage": True},)for chunk in stream:if chunk.choices and chunk.choices[0].delta.content:print(chunk.choices[0].delta.content, end="", flush=True)if chunk.usage:print("\n", chunk.usage)const stream = await client.chat.completions.create({model: "grafilab/qwen3.6-flash",messages: [{ role: "user", content: "Say hello in five words." }],stream: true,stream_options: { include_usage: true },});for await (const chunk of stream) {const delta = chunk.choices[0]?.delta?.content;if (delta) process.stdout.write(delta);if (chunk.usage) console.log("\n", chunk.usage);}The raw SSE stream ends with
data: [DONE]. -
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.
Verify
Section titled “Verify”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.
Troubleshooting
Section titled “Troubleshooting”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-runGET /v1/modelsand copy anidfrom 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/v1and clients append/chat/completions; Anthropic clients take the bare originhttps://llm.grafilab.aiand append/v1/messagesthemselves.

