error code and message:
Error reference
| Status | Code | What’s wrong | What to do |
|---|---|---|---|
| 400 | invalid_json | Body isn’t valid JSON | Fix your JSON syntax |
| 400 | validation_error | Bad parameter(s) | Check the details array (see below) |
| 401 | missing_api_key | No auth header | Add Authorization: Bearer nj_sk_... |
| 401 | invalid_api_key | Bad or revoked key | Check key starts with nj_sk_ |
| 402 | insufficient_credits | Out of credits | Add credits |
| 429 | rate_limit_exceeded | Too many requests | Wait Retry-After seconds |
| 502 | generation_failed | Upstream failed | Retry — not charged |
| 500 | internal_error | Server error | Retry |
Validation errors
400 errors include adetails array telling you exactly which fields are wrong:
Error handling code
Common mistakes
| Symptom | Cause | Fix |
|---|---|---|
validation_error on model | Typo in model ID (e.g. gpt5 instead of gpt-5) | Check available models for exact IDs |
validation_error on messages | Missing role or content field | Each message needs {"role": "user", "content": "..."} |
insufficient_credits | Balance is $0.00 | Add credits |
invalid_api_key | Key revoked or copied incorrectly | Keys start with nj_sk_. Create a new one in Developers |
| Empty streaming response | Not reading SSE stream correctly | See streaming example |
Proactive warnings
You don’t have to wait for a402 error. Every response includes a balance_warning when your balance drops below $5.00:
balance_warning in responses and alert yourself before running out. See Pricing for details.
Quick debug
| Output | Meaning |
|---|---|
200 | Working |
401 | Bad API key |
402 | No credits |