Code survey responses (one-call hero)
const url = 'https://api.surveycoder.io/v2/code';const options = { method: 'POST', headers: { 'X-Request-Id': '550e8400-e29b-41d4-a716-446655440000', 'Idempotency-Key': 'my-batch-2026-03-31-001', 'x-api-key': '<x-api-key>', 'Content-Type': 'application/json' }, body: '{"responses":[{"id":"R001","text":"I love Nike because of their innovation and comfort"},{"id":"R002","text":"Adidas has the best designs, especially the Originals line"},{"id":"R003","text":"Nike is overpriced, I switched to New Balance last year"},{"id":"R004","text":"I don\'t really care about brands, I just buy whatever is on sale"},{"id":"R005","text":"Puma has great collaborations with designers like Rihanna"}],"coding_type":"qualitative","language":"en"}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://api.surveycoder.io/v2/code \ --header 'Content-Type: application/json' \ --header 'Idempotency-Key: my-batch-2026-03-31-001' \ --header 'X-Request-Id: 550e8400-e29b-41d4-a716-446655440000' \ --header 'x-api-key: <x-api-key>' \ --data '{ "responses": [ { "id": "R001", "text": "I love Nike because of their innovation and comfort" }, { "id": "R002", "text": "Adidas has the best designs, especially the Originals line" }, { "id": "R003", "text": "Nike is overpriced, I switched to New Balance last year" }, { "id": "R004", "text": "I don'\''t really care about brands, I just buy whatever is on sale" }, { "id": "R005", "text": "Puma has great collaborations with designers like Rihanna" } ], "coding_type": "qualitative", "language": "en" }'Send an array of open-ended responses and receive AI-generated codes back in a single call. The pipeline:
- Creates a temporary project
- Generates (or imports) a codebook
- Runs multi-layer AI coding (Preparation -> Classification -> Review)
- Returns codebook + per-response codes
Sync vs Async:
- < 50 responses: synchronous — result returned inline.
-
= 50 responses: returns
202 Acceptedwith ajob_idfor polling.
Maximum 10,000 responses per request.
Authorizations
Section titled “Authorizations ”Parameters
Section titled “ Parameters ”Header Parameters
Section titled “Header Parameters ”Example
550e8400-e29b-41d4-a716-446655440000Client-generated request ID for tracing. Returned as-is in the
response X-Request-Id header.
Example
my-batch-2026-03-31-001Idempotency key for safe retries on write endpoints. If the same
key is sent within 24 hours, the server returns the cached response
and sets X-Idempotent-Replay: true.
Request Body required
Section titled “Request Body required ”object
Array of open-ended survey responses to code.
object
Unique respondent or response identifier (your system’s ID).
The verbatim open-ended response text.
Type of coding to apply:
qualitative— Theme-based coding with sentiment (default). Best for opinion questions.entity— Entity/brand extraction and normalization. Best for “which brands do you know?” questions.qualitative_topics— Topic grouping with forced Neutral sentiment. Best for “what topics were discussed?” questions.
ISO 639-1 language code for the responses. Affects codebook generation prompts.
Optional pre-defined codebook. When provided, the AI skips codebook generation and uses these codes directly. When omitted, the AI generates a codebook automatically via MapReduce pipeline.
object
Top-level groupings of codes.
object
Category name (e.g. “Product Quality”, “Customer Service”).
Individual codes within this category.
object
Code label.
Detailed definition to guide the AI classifier.
Expected sentiment polarity for this code.
Examples
Brand preference survey (5 responses)
{ "responses": [ { "id": "R001", "text": "I love Nike because of their innovation and comfort" }, { "id": "R002", "text": "Adidas has the best designs, especially the Originals line" }, { "id": "R003", "text": "Nike is overpriced, I switched to New Balance last year" }, { "id": "R004", "text": "I don't really care about brands, I just buy whatever is on sale" }, { "id": "R005", "text": "Puma has great collaborations with designers like Rihanna" } ], "coding_type": "qualitative", "language": "en"}Responses
Section titled “ Responses ”Synchronous result (< 50 responses)
Synchronous coding result (< 50 responses).
object
object
Generated or imported codebook (categories with nested codes).
A category with its nested codes, as returned in codebook results.
object
Database ID of the category.
Category name.
object
Database ID of the code.
Code label.
Sentiment polarity of this code.
Numeric identifier for the code (unique within question).
Number of responses assigned to this code.
Per-response coding results, in the same order as the input.
Coding output for a single response.
object
The response ID you provided in the request.
Codes assigned to this response. May be empty if the response could not be classified (garbage, too short, etc.). A response can have multiple codes if it mentions multiple themes.
object
Code label from the codebook.
Sentiment polarity of this assignment.
AI confidence in this code assignment:
high— clear match to code definition.medium— reasonable match, may benefit from review.low— uncertain match, flagged for review.
Number of credits consumed by this request.
ID of the temporary project created for this request.
ID of the question within the temporary project.
object
Always sync for inline results.
Examples
Coded brand preference responses
{ "success": true, "data": { "codebook": [ { "id": "cat_001", "name": "Brand Perception", "codes": [ { "id": "code_001", "name": "Innovation / Technology", "sentiment": "Positive", "code_number": 1, "frequency": 1 }, { "id": "code_002", "name": "Design / Aesthetics", "sentiment": "Positive", "code_number": 2, "frequency": 2 }, { "id": "code_003", "name": "Overpriced / Value concern", "sentiment": "Negative", "code_number": 3, "frequency": 1 }, { "id": "code_004", "name": "Price-driven / No brand loyalty", "sentiment": "Neutral", "code_number": 4, "frequency": 1 }, { "id": "code_005", "name": "Celebrity / Designer collaborations", "sentiment": "Positive", "code_number": 5, "frequency": 1 } ] } ], "results": [ { "id": "R001", "codes": [ { "name": "Innovation / Technology", "sentiment": "Positive", "confidence": "high" } ] }, { "id": "R002", "codes": [ { "name": "Design / Aesthetics", "sentiment": "Positive", "confidence": "high" } ] }, { "id": "R003", "codes": [ { "name": "Overpriced / Value concern", "sentiment": "Negative", "confidence": "high" } ] }, { "id": "R004", "codes": [ { "name": "Price-driven / No brand loyalty", "sentiment": "Neutral", "confidence": "medium" } ] }, { "id": "R005", "codes": [ { "name": "Celebrity / Designer collaborations", "sentiment": "Positive", "confidence": "high" } ] } ], "credits_used": 5, "project_id": "proj_abc123", "question_id": "q_def456" }, "meta": { "api_version": "v1", "mode": "sync" }}Headers
Section titled “Headers ”Echo of the client-supplied X-Request-Id, or a server-generated UUID.
Example
60Maximum requests allowed per minute for this API key.
Example
57Requests remaining in the current rate-limit window.
Example
1743436800Unix epoch second when the current rate-limit window resets.
Example
falseSet to true when the response is a cached replay of a previous
request that used the same Idempotency-Key.
Async job created (>= 50 responses)
Async job acceptance (>= 50 responses).
object
object
Unique job identifier for polling.
Initial status is always queued.
Rough estimate of processing time in seconds.
object
Always async for job-based processing.
Convenience URL for polling the job.
Example
{ "success": true, "data": { "job_id": "job_1a2b3c4d5e6f7a8b9c0d1e2f", "status": "queued", "estimated_seconds": 50 }, "meta": { "api_version": "v1", "mode": "async", "poll_url": "/v2/jobs/job_1a2b3c4d5e6f7a8b9c0d1e2f" }}Request body failed validation.
Standard error envelope.
object
object
Machine-readable error code. See the error reference for the full list.
Human-readable explanation of what went wrong.
Echo of the X-Request-Id header, when provided.
Link to documentation for this specific error code.
Example
{ "success": false, "error": { "code": "VALIDATION_ERROR", "message": "responses array is required and must not be empty", "doc_url": "https://docs.surveycoder.io/errors/validation-error" }}Missing or invalid API key.
Standard error envelope.
object
object
Machine-readable error code. See the error reference for the full list.
Human-readable explanation of what went wrong.
Echo of the X-Request-Id header, when provided.
Link to documentation for this specific error code.
Example
{ "success": false, "error": { "code": "UNAUTHORIZED", "message": "x-api-key header is required", "doc_url": "https://docs.surveycoder.io/errors/unauthorized" }}Organization does not have enough credits.
Standard error envelope.
object
object
Machine-readable error code. See the error reference for the full list.
Human-readable explanation of what went wrong.
Echo of the X-Request-Id header, when provided.
Link to documentation for this specific error code.
Example
{ "success": false, "error": { "code": "INSUFFICIENT_CREDITS", "message": "Need 500 credits, have 120", "doc_url": "https://docs.surveycoder.io/errors/insufficient-credits" }}API key lacks the required scope, is revoked, or has expired.
Standard error envelope.
object
object
Machine-readable error code. See the error reference for the full list.
Human-readable explanation of what went wrong.
Echo of the X-Request-Id header, when provided.
Link to documentation for this specific error code.
Examples
Missing write scope
{ "success": false, "error": { "code": "INSUFFICIENT_SCOPE", "message": "Requires 'write' scope", "doc_url": "https://docs.surveycoder.io/errors/insufficient-scope" }}Revoked key
{ "success": false, "error": { "code": "KEY_REVOKED", "message": "API key has been revoked", "doc_url": "https://docs.surveycoder.io/errors/key-revoked" }}Rate limit exceeded. Retry after the reset window.
Standard error envelope.
object
object
Machine-readable error code. See the error reference for the full list.
Human-readable explanation of what went wrong.
Echo of the X-Request-Id header, when provided.
Link to documentation for this specific error code.
Example
{ "success": false, "error": { "code": "RATE_LIMITED", "message": "Rate limit exceeded", "doc_url": "https://docs.surveycoder.io/errors/rate-limited" }}Headers
Section titled “Headers ”Example
60Maximum requests allowed per minute for this API key.
Example
57Requests remaining in the current rate-limit window.
Example
1743436800Unix epoch second when the current rate-limit window resets.
Unexpected server error.
Standard error envelope.
object
object
Machine-readable error code. See the error reference for the full list.
Human-readable explanation of what went wrong.
Echo of the X-Request-Id header, when provided.
Link to documentation for this specific error code.
Example
{ "success": false, "error": { "code": "INTERNAL_ERROR", "message": "Failed to process coding request", "doc_url": "https://docs.surveycoder.io/errors/internal-error" }}