Errors
Every error shares one JSON envelope, so you can handle them uniformly:
{
"error": {
"type": "invalid_request",
"message": "Query parameter 'q' is required.",
"request_id": "a1b2c3d4e5f6a7b8"
}
}
type— a stable, machine-readable code (switch on this, not onmessage).message— a human-readable explanation.request_id— the same value as theX-Request-Idresponse header; quote it to support.
Error types
| Status | type |
When it happens |
|---|---|---|
| 400 | invalid_request |
A required parameter is missing or malformed (e.g. an empty q). |
| 401 | unauthorized |
No API key, or an invalid / revoked key. |
| 403 | insufficient_scope |
The key exists but lacks the search scope required by the endpoint. |
| 403 | forbidden |
The key is not permitted to perform the action. |
| 402 | payment_required |
No active Neuji membership. |
| 402 | insufficient_credits |
Your API credit balance is empty. Buy credits or enable auto-reload. |
| 429 | rate_limited |
You exceeded the rate limit. See Rate limits. |
Billing-related headers
A credit-billed endpoint also returns your balance on every response, including the error responses above:
| Header | Meaning |
|---|---|
X-Credits-Balance |
Remaining credit balance, in minor currency units (e.g. cents). |
X-Credits-Requests-Remaining |
Approximate number of further requests that balance covers. |
Reading errors
curl -s "https://api.neuji.com/v1/search" \ -H "Authorization: Bearer $NEUJI_API_KEY" # => HTTP 400 {"error":{"type":"invalid_request","message":"Query parameter 'q' is required.","request_id":"…"}}
using System.Text.Json; var res = await http.GetAsync("https://api.neuji.com/v1/search"); // missing q if (!res.IsSuccessStatusCode) { using var doc = JsonDocument.Parse(await res.Content.ReadAsStringAsync()); var err = doc.RootElement.GetProperty("error"); Console.WriteLine($"{(int)res.StatusCode} {err.GetProperty("type").GetString()}: {err.GetProperty("message").GetString()}"); }
const res = await fetch("https://api.neuji.com/v1/search", { headers: { Authorization: `Bearer ${process.env.NEUJI_API_KEY}` }, }); if (!res.ok) { const { error } = await res.json(); console.error(`${res.status} ${error.type}: ${error.message} (request ${error.request_id})`); }