New

Now in Claude, ChatGPT, Cursor & more with our MCP server

Back to docs
Collecting Responses

Headless API Overview

Manage interviews programmatically with the Koji REST API — start, message, and complete interviews from your own code.

The Headless API lets you run Koji interviews entirely from your own backend. Instead of sending participants to a link or embedding an iframe, you make REST API calls to start conversations, send messages, and mark interviews as complete. This is ideal for building fully custom interview experiences or integrating Koji into existing workflows.

What Is the Headless API?

Think of it as Koji without the front end. Your application controls the entire flow:

  1. Start an interview by calling the start endpoint. Koji returns an interview ID, a session token, and the first message.
  2. Exchange messages by sending participant responses to the message endpoint. Koji replies with follow-up questions.
  3. Complete the interview by calling the complete endpoint. Koji triggers its analysis pipeline and generates insights.

Your participants never interact with Koji's interface directly — they interact with whatever UI you build.

Plan Availability

The Headless API is available on all Koji plans. Usage is controlled by your credit balance — each interview started via the API consumes credits just like any other interview. See your account settings for current credit balance and usage.

Getting Started

Authentication

All API requests require a Bearer token in the Authorization header. You can generate API keys from your project settings.

Authorization: Bearer YOUR_API_KEY

Your API key must have the appropriate permissions for the endpoints you want to use. See API Authentication for setup instructions.

Base URL

All endpoints are available at:

https://yourdomain.com/api/v1/interviews

Core Endpoints

Start an Interview

POST /api/v1/interviews/start

Creates a new interview and returns the opening message.

Request body:

{
  "respondent": {
    "external_id": "crm-contact-456",
    "display_name": "Jane Smith",
    "metadata": {
      "source": "crm-integration",
      "segment": "enterprise"
    }
  },
  "mode": "text",
  "locale": "en"
}

Response:

{
  "interview_id": "int_abc123",
  "session_token": "stk_xyz789",
  "initial_message": "Hi Jane! Thanks for taking the time..."
}

The respondent object is optional. If provided, it accepts these fields:

FieldPurpose
external_idYour own identifier for matching against your CRM or database
display_nameUsed to greet the participant and shown in your results
metadataFlexible key-value pairs for segmentation and tracking

The mode field is optional and defaults to text. The locale field is optional and defaults to the study's configured language.

Send a Message

POST /api/v1/interviews/:id/message

Sends the participant's response and receives the next question.

Request body:

{
  "message": "I've been using the product for about six months now..."
}

Response:

{
  "message": {
    "role": "assistant",
    "content": "That's great to hear. What was your initial impression when you first started using it?"
  },
  "turn_count": 3,
  "is_complete": false
}

The is_complete flag tells you whether the interviewer has gathered enough information and is ready to wrap up. You can use this to decide when to call the complete endpoint.

Complete an Interview

POST /api/v1/interviews/:id/complete

Marks the interview as finished and triggers Koji's analysis pipeline.

Response:

{
  "status": "completed",
  "quality_score": 4.2
}

Once completed, the interview appears in your project dashboard with a full transcript, quality score, and generated insights.

Get Interview Details

GET /api/v1/interviews/:id

Retrieve the full transcript and metadata for a specific interview.

Structured Questions via API

If your study includes structured questions (scales, multiple choice, ranking, or yes/no), the AI interviewer will present these during the conversation. When using the Headless API, structured question prompts appear in the assistant's message content. Your UI should handle rendering appropriate input widgets based on the question type indicated in the response.

Common Use Cases

In-App Feedback

Embed a feedback flow inside your own product. When a user triggers a feedback prompt, your backend starts a Koji interview, then your front end presents the conversation in your own UI components.

CRM Integration

Connect Koji to your CRM pipeline. When a deal reaches a certain stage, automatically trigger an interview with the contact. Responses flow back into the CRM record.

Chatbot Handoff

Route specific conversation topics from your existing chatbot to a Koji interview. The participant continues the conversation naturally while Koji handles the research-quality follow-up questions.

Batch Research

Combine CSV import with the Headless API for large-scale studies. Import your participant list, then programmatically start and manage interviews for each person.

Rate Limiting

The API enforces a rate limit of 60 requests per minute to ensure fair usage across all customers. If you exceed the limit, you will receive a 429 Too Many Requests response. Rate limit information is included in response headers:

HeaderDescription
X-RateLimit-LimitMaximum requests allowed per window
X-RateLimit-RemainingRequests remaining in the current window
X-RateLimit-ResetUnix timestamp when the window resets

Build retry logic into your integration to handle rate limit responses gracefully.

Error Handling

All error responses follow a consistent format:

{
  "error": "Description of what went wrong"
}

Common status codes:

CodeMeaning
401Missing or invalid API key
403API key lacks the required permission, or origin not allowed
404Interview not found
429Rate limit exceeded

Best Practices

  1. Store interview IDs. Save the interview_id returned by the start endpoint so you can continue the conversation and retrieve results later.
  2. Respect the is_complete flag. When the response indicates the interview is ready to wrap up, call the complete endpoint to trigger analysis.
  3. Handle errors gracefully. Implement retry logic for transient failures and surface clear error messages to your users.
  4. Secure your API key. Never expose your API key in client-side code. All API calls should go through your backend.

Next Steps

Related Articles

Exporting Research Data from Koji: CSV, JSON, and Transcript Access

A complete guide to every way you can get your interview data out of Koji — from one-click CSV downloads to real-time webhook pipelines.

Send Research Insights to Slack: Real-Time Customer Interview Notifications via Webhooks

Pipe customer interview insights from Koji into your Slack workspace in real time. Use Koji webhooks to notify a #research channel the moment an interview completes, post quote highlights to #product-feedback, or alert #cs-alerts when a churn signal is detected. Step-by-step setup with a working Slack incoming webhook recipe.

API Authentication

Learn how to authenticate with the Koji API using API keys and Bearer tokens.

User Research API: Embed AI Interviews into Any Product or Workflow

How to use Koji's User Research API to run AI-moderated interviews from your own backend. Covers REST endpoints, the embed widget, webhooks, authentication, rate limits, and headless interview patterns.

Sync Koji Customer Interviews to HubSpot: Live Insights on Every Contact

Push Koji interview transcripts, themes, and quality scores onto HubSpot contact and company records in real time using webhooks and the HubSpot API.

Starting Interviews via API

Use the POST /start endpoint to programmatically launch interviews from your application.

Research Automation: How to Build Real-Time Research Pipelines with Webhooks

Koji webhooks push interview and report data to your systems the instant something happens — enabling Slack alerts, CRM sync, automated tagging, and fully automated research pipelines that operate without manual intervention.

Using the Embed Widget

Add a Koji interview to your website using an embeddable iframe with configuration options and event listeners.

Structured Questions in AI Interviews

Mix quantitative data collection — scales, ratings, multiple choice, ranking — with AI-powered conversational follow-up in a single interview.