{"site":{"name":"Koji","description":"AI-native customer research platform that helps teams conduct, analyze, and synthesize customer interviews at scale.","url":"https://www.koji.so","contentTypes":["blog","documentation"],"lastUpdated":"2026-11-27T03:05:12.807Z"},"content":[{"type":"documentation","id":"0b88ef82-b556-4015-8d53-e0c15e2fc798","slug":"common-error-codes","title":"Common Error Codes","url":"https://www.koji.so/docs/common-error-codes","summary":"Troubleshooting reference for the Koji Headless API. Documents the JSON error envelope, a status code overview, a consolidated table of every distinct error string across all endpoints with fixes, SSE mid-stream error frames, and a debugging checklist.","content":"# Common Error Codes\n\nEvery failure in the Headless API is designed to be diagnosable from two things: the HTTP status and the `error` string in the body. This page collects all of them in one place, with fixes.\n\n---\n\n## The error envelope\n\n- Every error response is JSON with an `error` string: `{ \"error\": \"...\" }`.\n- Some errors add fields: `retry_after` (rate limit), `message` and `reason` (start-endpoint availability errors), `current` and `limit` (quota errors), `closed` (paused studies).\n- There is no `code` or `details` field. Match on the HTTP status and the `error` string.\n- The message endpoint can also fail mid-stream: the final SSE frame is then `{\"type\":\"error\",\"error\":\"Stream processing failed\"}` with the HTTP status already committed as 200.\n\nA typical error body:\n\n```json\n{\n  \"error\": \"Rate limit exceeded\",\n  \"retry_after\": 42\n}\n```\n\n---\n\n## Status code overview\n\n| Status | Meaning |\n|---|---|\n| 200 | Success (message: SSE stream; complete/get: JSON) |\n| 201 | Interview created (start) |\n| 400 | Bad request. Missing content, inactive interview, or invalid fields |\n| 401 | Authentication failed. Bad/missing API key or session token |\n| 403 | Authenticated but not allowed. Missing permission, origin blocked, study closed, wrong project, or plan/entitlement |\n| 404 | Interview or project not found |\n| 429 | Rate limit exceeded or interview quota reached |\n| 500 | Server error. Retry with backoff |\n\n---\n\n## Every error string\n\nThis table consolidates every distinct error the API returns, across the start, message, complete, read, and embed bootstrap endpoints. The four per-permission 403s are collapsed into one row: the real string names the specific scope, for example `API key does not have interview:read permission`.\n\n| Status | `error` | When it happens | How to fix it |\n|---|---|---|---|\n| 400 | `Interview is not active` | The interview was already completed or abandoned | The interview was already completed or abandoned. Start a new one. |\n| 400 | `Message content is required` | `content` was missing or not a string | Send a JSON body with a `content` string field. |\n| 401 | `Missing or invalid authorization header` | No `Authorization: Bearer` header sent | Send `Authorization: Bearer pk_live_...` on every request. |\n| 401 | `Invalid API key` | The key does not exist, is malformed, is inactive, or has expired | Check the key starts with `pk_live_`, was copied in full, and has not been revoked or expired. Create a new key if in doubt. |\n| 401 | `Missing X-Session-Token header` | The session token header was not sent | Send the `session_token` from the start response in the `X-Session-Token` header. |\n| 401 | `Invalid session token` | The token does not match this interview's respondent | Use the exact `session_token` issued for this interview id. Tokens are not interchangeable between interviews. |\n| 403 | `API key does not have <permission> permission` | The key was created without the permission this endpoint requires | Create a key that includes the scope the endpoint requires. See [API Key Permissions](/docs/api-permissions). |\n| 403 | `Origin not allowed` | The browser's Origin header does not match the key's allowed origins | Add your site's origin (with scheme) to the key's allowed origins, or use a wildcard entry. See [API Authentication](/docs/api-authentication). |\n| 403 | `Headless API access requires an Interviews plan or higher.` | The study owner's plan doesn't include API access. The headless API, API keys and the MCP connector are included on the Interviews and Enterprise plans only | Move the study owner's workspace to the Interviews or Enterprise plan. Retrying won't help. |\n| 403 | `This study is no longer accepting responses` | The study is paused or closed | The study is paused or closed. Reopen it from the dashboard. |\n| 403 | `unavailable` | The study cannot accept responses right now (owner account state) | The study cannot accept responses right now. Inspect the `message` and `reason` fields for the specific cause. |\n| 403 | `Interview does not belong to this project` | The interview belongs to a different study than the API key | The interview id and the API key point at different studies. Use the key for the study that owns the interview. |\n| 403 | `API key does not match project` | The key belongs to a different study | Use the API key created for the same study as the embed project id. |\n| 404 | `Interview not found` | Unknown interview id (or the interview was deleted) | Check the interview id. It must come from a start response for the same study. |\n| 404 | `Project not found` | Unknown project id | Check the project id in the embed URL. |\n| 429 | `Rate limit exceeded` | The key exceeded its per-minute request limit | Wait `retry_after` seconds, then retry. See [Rate Limits and CORS](/docs/rate-limits-and-cors). |\n| 429 | `interview_limit_reached` | The study hit its response limit or the owner's interview quota | Raise the study's response limit or the owner's quota. Retrying will not help. |\n| 500 | `Internal server error` | Unexpected server failure. Safe to retry with backoff | Retry with exponential backoff. If it persists, contact support. |\n\nPer-endpoint error tables, including which extra fields accompany each error, live on the endpoint pages: [Starting Interviews](/docs/starting-interviews-via-api), [Sending Messages](/docs/sending-messages-via-api), and [Completing Interviews](/docs/completing-interviews-via-api).\n\n---\n\n## SSE stream errors\n\nThe message endpoint streams its reply as Server-Sent Events, which means a failure can happen after the HTTP status is already committed as 200. In that case the last frame of the stream is:\n\n```\ndata: {\"type\":\"error\",\"error\":\"Stream processing failed\"}\n```\n\nYour SSE parser must treat an `error` frame as terminal for that message. Do not rely on the HTTP status alone for the message endpoint; check frame types. See [Sending Messages via API](/docs/sending-messages-via-api) for a parser that handles this correctly.\n\n---\n\n## Debugging checklist\n\n- Key rejected? Confirm it starts with `pk_live_`, is active (not revoked), and hasn't expired.\n- `Invalid session token`? Send the exact `session_token` from the start response in the `X-Session-Token` header, for the same interview id.\n- `Origin not allowed`? Your key restricts origins; add your site's origin (with scheme) or use a wildcard entry.\n- `Interview is not active`? The interview was already completed. Start a new one.\n- Missing permission? The key was created with a narrowed permission set; create a key that includes the scope you need.\n- `Headless API access requires an Interviews plan or higher.`? The study owner is on Free or Insights. The API needs the Interviews or Enterprise plan.\n- 429? Check `retry_after` and the `X-RateLimit-*` headers; distinguish rate limits from `interview_limit_reached` quota errors.\n\n---\n\n## FAQ\n\n### Is there an error code field I can switch on?\n\nNo. There is no `code` or `details` field. Match on the HTTP status plus the `error` string. The strings in the table above are the exact strings the handlers return.\n\n### I got a 429. Should I retry?\n\nDepends on the string. `Rate limit exceeded` resolves after `retry_after` seconds. `interview_limit_reached` is a quota error and retrying will not help. See [Rate Limits and CORS](/docs/rate-limits-and-cors).\n\n### Why do I get 401 on message but 200 on start with the same key?\n\nStart needs only the API key. Message additionally needs the `X-Session-Token` header with the exact token from the start response. A missing or mismatched token fails with 401 even though the key is valid.\n\n### The error says the interview belongs to a different project. What happened?\n\nInterview ids are study-scoped, and so are API keys. You are calling with a key from one study and an interview id from another. Use the key for the study that owns the interview.","category":"Troubleshooting","lastModified":"2026-10-15T04:10:21.14512+00:00","metaTitle":"Common Error Codes | Koji Headless API","metaDescription":"Troubleshoot the Koji API: the {\"error\": \"...\"} envelope, status code overview, every distinct error string with a fix, SSE error frames, and a checklist.","keywords":["error codes","api errors","troubleshooting","401 unauthorized","403 forbidden","429 rate limit"],"aiSummary":"Troubleshooting reference for the Koji Headless API. Documents the JSON error envelope, a status code overview, a consolidated table of every distinct error string across all endpoints with fixes, SSE mid-stream error frames, and a debugging checklist.","aiPrerequisites":["api-authentication"],"aiLearningOutcomes":["Parse the { \"error\": ... } envelope and its extra fields","Map HTTP status codes to failure classes","Look up any error string and apply its fix","Handle SSE error frames that arrive after HTTP 200"],"aiDifficulty":"intermediate","aiEstimatedTime":"8 min"}],"pagination":{"total":1,"returned":1,"offset":0}}