API reference
Endpoints, errors and limits
All endpoints live under https://infermesh.dev/v1. Authenticate with Authorization: Bearer <key> or x-api-key: <key>. Keys carry scopes; an endpoint rejects keys without its scope.
Endpoints
Creating keys programmatically
With an existing key that has the keys scope, child keys inherit its account; they can't gain scopes, exceed the parent's spend cap or its rate limit. Without a key, sign the message from /v1/keys/nonce with your wallet.
curl https://infermesh.dev/v1/keys/generate \
-H "Authorization: Bearer sk-infer-YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{ "name": "ci-runner", "scopes": ["inference"], "spend_cap": "25", "spend_cap_period": "daily", "rate_limit_rpm": 120 }'The response contains key exactly once. Scopes: inference, account, keys, mcp.
Errors
OpenAI-style endpoints return { "error": { "message", "type", "param", "code" } }; /v1/messages returns Anthropic's { "type": "error", "error": { "type", "message" } }. Both include the InferMesh code and machine-readable extras.
When credits run out mid-stream
A streaming request that exhausts your balance is cut off cleanly: the gateway stops reading from the provider and sends a final error event, then ends the stream.
data: {"error":{"message":"Credits ran out mid-stream; the response was truncated. Add credits at https://infermesh.dev/compute","type":"insufficient_credits","param":null,"code":"insufficient_credits","replenish_url":"https://infermesh.dev/compute"}}
data: [DONE]Anthropic-style streams receive the same error as an event: error. Clients should treat it like any stream error; the partial output already received is valid.
Rate limits and spend caps
- Each key has a requests-per-minute limit (default 600, up to 10,000) enforced as a token bucket that allows bursts of a quarter of the per-minute limit (at least 5 requests).
- Spend caps apply per UTC day, per UTC month or for the key's lifetime, and count in-flight reservations so concurrent requests can't overshoot.
- Agent keys are capped at the agent's daily spend limit.
Failover