← Back to home

API Reference

Last updated: August 5, 2026

The MeshCode API lets you call MeshCode's models from any script, server, or third-party tool — no editor or desktop app required. It's an OpenAI-compatible /v1/chat/completions endpoint gated by an API key instead of a login session, in the same spirit as OpenRouter's key-based API. Requests are billed against your prepaid wallet balance (pay-as-you-go, no subscription).

1. Get an API key

Create and manage keys from app.meshcode.ai/account/api-keys. Each key can optionally carry its own spend cap (with a daily/weekly/monthly reset), on top of your account's wallet balance — useful for handing a scoped key to a script or teammate. Keys look like sk-mesh-... and are shown in full only once, at creation time.

2. Authentication

Send your key as a bearer token on every request:

Authorization: Bearer sk-mesh-...

Requests without a valid key, or with a revoked/expired key, get a 401.

3. Base URL

https://api.meshcode.ai

4. Chat completions

POST /v1/chat/completions — OpenAI-compatible request/response shape. Instead of naming a specific upstream model, you pick one of three routing tiers; MeshCode resolves it server-side to whichever real model is currently best for that tier (with automatic failover), so the tier stays stable even as the underlying model changes.

model Good for
flow Fast, cheap, everyday requests
logic Harder reasoning, still text-only
architect Highest-capability tier for complex tasks
curl https://api.meshcode.ai/v1/chat/completions \
  -H "Authorization: Bearer $MESHCODE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "flow",
    "messages": [{ "role": "user", "content": "Hello!" }]
  }'

5. Check your balance

GET /v1/key — returns your current wallet balance, plus the calling key's own spend cap and how much of it is left (if the key has one). Use this to check headroom before a batch job instead of finding out via a 402.

curl https://api.meshcode.ai/v1/key \
  -H "Authorization: Bearer $MESHCODE_API_KEY"
{
  "data": {
    "label": "my key",
    "balanceMicroUsd": 4820000,
    "limitMicroUsd": 10000000,
    "limitRemainingMicroUsd": 7000000,
    "spentMicroUsd": 3000000,
    "resetPeriod": "monthly"
  }
}

All amounts are in micro-USD (1,000,000 = $1). limitMicroUsd and the fields derived from it are null when the key has no cap of its own — in that case only the wallet balance gates spend.

6. Errors

Status Meaning
400 Invalid request body, or an unsupported model value
401 Missing, invalid, revoked, or expired API key
402 Wallet balance too low, or the key's own spend cap was hit — top up or check /v1/key
429 Too many requests — back off and retry

7. Questions

Email help@meshcode.ai — we're a small team and read every message.