# Send a chat completion with ZeroGPU's OpenAI-compatible API

ZeroGPU's agent storefront serves an OpenAI-compatible chat completions API: send an OpenAI-style request to `https://agents.zerogpu.ai/zcj/t80wy33288ba/zeroclick/v1/chat/completions` with a storefront credential, and no ZeroGPU account or API key. Each call draws on prepaid Credits by the tokens it uses, at the rate of the model you set. On LFM2.5-1.2B-Instruct that is $0.02 per million tokens for input and $0.05 per million tokens for output.

## At a glance

- **Endpoint:** `POST https://agents.zerogpu.ai/zcj/t80wy33288ba/zeroclick/v1/chat/completions`
- **Headers:** `Authorization: Bearer <access token>` and `Content-Type: application/json`
- **Body:** `model` (required on every call, because it picks the model and the rate) and `messages` (at least one `{role, content}`)
- **Price:** per token on Credits, at the model's input and output rates. For example, LFM2.5-1.2B-Instruct costs input $0.02 per million tokens and output $0.05 per million tokens.
- **Payment:** you buy Credits once. The purchase answers with a 402, which is the price quote. You pay it over x402 or MPP (wallet rails that settle in USDC) or by card, then retry. Calls then draw on that credit rather than quoting a price of their own.
- **Credits minimum:** $0.01 on a wallet rail and $0.50 by card
- **Response:** a `chat.completion` object with `choices` and `usage`. The `zc-billing` header reports what the call drew from your balance.
- **Full purchase flow:** [the buyer skill](https://agents.zerogpu.ai/zcj/t80wy33288ba/SKILL.md)

## Send your first chat completion

1. Get an access token. Reuse a ZeroClick agent credential if you already hold one, because one registration works at every ZeroClick storefront. Otherwise, register and then exchange the returned `identity.assertion` for a token:

   ```bash
   curl -sS https://agents.zerogpu.ai/zcj/t80wy33288ba/agent/identity \
     -H 'Content-Type: application/json' -d '{"type":"anonymous"}'

   curl -sS https://agents.zerogpu.ai/zcj/t80wy33288ba/oauth2/token \
     -H 'Content-Type: application/x-www-form-urlencoded' \
     -d grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer \
     --data-urlencode "assertion=$ASSERTION"
   ```

   The exchange returns `access_token`. Store the registration privately. Do not store the token, which lasts only minutes; re-run the exchange when it expires. An agent acting for a person should follow [the identity recipe](https://agents.zerogpu.ai/zcj/t80wy33288ba/auth.md) instead, which covers Link identity and claiming the credential to a verified email.

2. Buy Credits. In `https://agents.zerogpu.ai/zcj/t80wy33288ba/manifest.json`, take `purchase.url` from the plan whose `slug` is `credits`, then send:

   ```bash
   curl -sS -X POST "https://agents.zerogpu.ai/zcj/t80wy33288ba/plans/{planId}/purchase" \
     -H "Authorization: Bearer $ACCESS_TOKEN" \
     -H 'Content-Type: application/json' \
     -d '{"amountUsd": "<whole-cent amount>"}'
   ```

   The storefront answers with a 402. Its body carries `payment.amountUsd`, the `plan` and a challenge for each rail. Pay it with your x402 or MPP client, or by card, and retry the same request. On MPP, `Authorization` carries the payment credential, so send the token as `ZC-Agent-Authorization: Bearer <token>` instead. A successful purchase returns `purchased: true` and `access`.

3. Send the completion with `model` set:

   ```bash
   curl -sS https://agents.zerogpu.ai/zcj/t80wy33288ba/zeroclick/v1/chat/completions \
     -H "Authorization: Bearer $ACCESS_TOKEN" \
     -H 'Content-Type: application/json' \
     -d '{"model": "LFM2.5-1.2B-Instruct", "max_tokens": 60, "messages": [{"role": "user", "content": "Summarize in one sentence: Our support queue doubled after the launch, mostly password resets and billing questions, and the median first response time rose from two hours to five."}]}'
   ```

   The example response below is from the same body sent with `Authorization: Receipt <receiptId>` in place of the bearer.

   ```json
   {"object": "chat.completion", "model": "LFM2.5-1.2B-Instruct",
    "choices": [{"index": 0, "message": {"role": "assistant", "content": "The support queue increased significantly post-launch due to high demand for pas…"}, "finish_reason": "stop"}],
    "usage": {"prompt_tokens": 47, "completion_tokens": 47, "total_tokens": 94}}
   ```

   The example drew $0.000003 from credit.

4. Read the result. The answer is in `choices[0].message.content` and the token counts are in `usage`. The `zc-billing` response header has the form `{"status":"settled","fundingSource":"credit","chargedUsd":"…","remainingCreditUsd":"…"}`. In it, `chargedUsd` is what this call drew from your balance and `remainingCreditUsd` is the balance after the call.

## Test without registering

A receipt is a small credit bought without registering, and it suits a first test. Send the Credits `purchase.url` the amount the manifest lists as `purchase.anonymousCredit.amountUsd`, with no bearer:

```bash
curl -sS -X POST "https://agents.zerogpu.ai/zcj/t80wy33288ba/plans/{planId}/purchase" \
  -H 'Content-Type: application/json' \
  -d '{"amountUsd": "<purchase.anonymousCredit.amountUsd from the manifest>"}'
```

The storefront answers with a 402. Settle it on a wallet rail, retry the same request, and save the `receiptId` from the response privately. Then send `Authorization: Receipt <receiptId>` in place of the bearer. Each receipt spends only its own balance, and receipts cannot be topped up. If you lose the receipt, you lose its remaining credit. Larger amounts and top-ups need a registered credential.

## Choose a model

Three of the models this endpoint serves, with the uses their catalog listings describe. `model` takes the name exactly as written.

| Use, as the catalog listing describes it | `model` | Rate on Credits |
| --- | --- | --- |
| Chat, instruction following, routing | `LFM2.5-1.2B-Instruct` | input $0.02 per million tokens, output $0.05 per million tokens |
| Summarization of long text | `llama-3.1-8b-instruct-fast` | input $0.15 per million tokens, output $0.28 per million tokens |
| Reasoning, coding, multilingual text | `qwen3-30b-a3b-fp8` | input $0.10 per million tokens, output $0.45 per million tokens |

## What is charged and when

- Nothing is charged until you pay the purchase 402, so it is safe to stop before paying. Unused Credits stay on your balance.
- Calls draw on credit by tokens. There is no per-call payment, and a call without a credential is refused rather than priced.
- Top up with `POST https://agents.zerogpu.ai/zcj/t80wy33288ba/extend` and `{"amountUsd": "<whole-cent amount>"}`. Top-ups use the same one-402 payment.
- A registered anonymous credential that is never claimed lapses within days, and Credits bought on it lapse with it. This applies to a registered credential, not to a receipt. Claim the credential to a verified email to keep them.

## Errors

| Code | Meaning | Action |
| --- | --- | --- |
| `401 bearer_required` | No credential was sent | Register (step 1) and retry with the bearer |
| `401 invalid_token`, `token_expired` | The access token expired | Re-exchange the stored assertion |
| `403 plan_required` | The credential holds no Credits | Buy Credits (step 2), then retry |
| `usage_exhausted` | The credit balance is used up | Top up with `POST /extend` |
| `receipt_credit_exhausted` | The receipt's balance cannot cover the call | Buy a new receipt, or buy Credits with a credential |
| `400` | Malformed JSON, or `model` or `messages` missing | Fix the body |
| `420 context_length_exceeded` | The input exceeds the model's context limit | Shorten `messages` |
| `429` | The rate limit was reached, counted per agent | Wait `retry-after` seconds, then retry |

## Frequently asked questions

### Do I need a ZeroGPU account or API key to use the API?

No. Through the storefront you call with a ZeroClick agent credential, sent as `Authorization: Bearer`, or with an anonymous receipt. The storefront handles identity and payment, and you send no ZeroGPU key.

### How much does one chat completion cost?

A call costs the tokens it uses multiplied by the model's input and output rates on Credits. On LFM2.5-1.2B-Instruct those rates are $0.02 per million tokens for input and $0.05 per million tokens for output. The example above drew $0.000003 from credit.

### Can I buy inference credits with USDC?

Yes. You can pay the Credits purchase over x402 (Base USDC) or MPP (Tempo USDC) from $0.01. You can also pay by card from $0.50, and a card purchase also needs a registered credential.

### How do I check my remaining credit?

Each response's `zc-billing` header carries `remainingCreditUsd`. You can also send `GET https://agents.zerogpu.ai/zcj/t80wy33288ba/agent/entitlements` with your bearer, which lists your plans with their remaining credit.

### Where are the other models and tasks documented?

[The services list](https://agents.zerogpu.ai/zcj/t80wy33288ba/services) gives every model with its description and prices, and [the buyer skill](https://agents.zerogpu.ai/zcj/t80wy33288ba/SKILL.md) covers buying and recovery for all of them.

## Keep reading

- [Buyer skill](https://agents.zerogpu.ai/zcj/t80wy33288ba/SKILL.md): the full purchase flow and recovery
- [Identity](https://agents.zerogpu.ai/zcj/t80wy33288ba/auth.md): registering, claiming and exchanging a credential
- [How to pay](https://agents.zerogpu.ai/zcj/t80wy33288ba/payment.md): rails, Credits and top-ups
- [Error reference](https://agents.zerogpu.ai/zcj/t80wy33288ba/errors.md): every code and what to do
- [API reference](https://agents.zerogpu.ai/zcj/t80wy33288ba/openapi.json): the chat completions and responses schemas

---

Updated 2026-10-14. All ZeroGPU guides: https://agents.zerogpu.ai/guides.md. Storefront: https://agents.zerogpu.ai/zcj/t80wy33288ba/llms.txt.
