> ## Documentation Index
> Fetch the complete documentation index at: https://humain.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Error codes

> All API errors follow a consistent JSON shape with a machine-readable code, a human-readable message, and optional details.

## Error response shape

Every error response uses the same JSON envelope:

```json theme={null}
{
  "error": "SCREAMING_SNAKE_CASE_CODE",
  "message": "Human-readable description of what went wrong.",
  "details": {}
}
```

**error** `string` *required*

Machine-readable error code in `SCREAMING_SNAKE_CASE`. Use this field in `switch` statements
and retry logic — never parse the `message` string programmatically.

**message** `string` *required*

Human-readable description for logging and debugging. This string may change between API
versions — do not rely on its exact content.

**details** `object`

Additional error-specific fields. May be an empty object `{}`. See the table below for
codes that include structured details.

## Error codes reference

| HTTP | Code | When it occurs | What to do |
| - | - | - | - |
| 400 | `INPUT_REJECTED` | Guardrail rule or FraudGuard blocked the user's input | Show a neutral message; do not retry |
| 400 | `SESSION_ENDED` | Session already closed or time limit reached | Open a new session |
| 400 | `MISSING_REQUIRED_VARIABLE` | A `{{variable}}` referenced by the persona was not provided in `conversation_initiation_data.variables` at session open | Include the missing variable; see [Dynamic variables](https://humain.mintlify.site/guides/dynamic-variables.md) |
| 400 | `INVALID_MODE` | Called `webrtc/offer` on a session that isn't `voice` or `voip` | Open the session with the correct `mode` |
| 400 | `INVALID_SDP` | The SDP offer sent to `webrtc/offer` could not be parsed | Check `RTCPeerConnection.createOffer()` output |
| 400 | `INVALID_CANDIDATE` | The ICE candidate sent to `webrtc/ice` could not be parsed | Check the candidate string from `onicecandidate` |
| 400 | `NO_WEBRTC_SESSION` | `webrtc/ice` called before `webrtc/offer` for this session | Call `webrtc/offer` first |
| 400 | `WEBRTC_RECONNECT_REQUIRED` | The peer connection closed; `webrtc/ice` can't add candidates to it | Call `webrtc/offer` again to re-negotiate |
| 401 | `UNAUTHENTICATED` | Missing, malformed, or revoked device token | Check credential format and expiry |
| 402 | `PLAN_LIMIT_REACHED` | Workspace has hit its plan's session or message ceiling | Upgrade plan or reduce usage |
| 403 | `KIOSK_INACTIVE` | The kiosk's status in the admin panel is not *active* | Activate the kiosk in the admin panel |
| 403 | `CREDENTIAL_BLOCKED` | FraudGuard blocked this credential due to suspicious activity | Wait until `blocked_until`; contact support if incorrect |
| 404 | `SESSION_NOT_FOUND` | The session manifest isn't in Redis — expired, never created, or the agent restarted before the first WS/WebRTC connection | Open a new session |
| 422 | `VALIDATION_ERROR` | Request body failed schema validation | Fix the request body per `details` field |
| 429 | `RATE_LIMITED` | Too many requests — back off and retry | Wait `retry_after_seconds` before retrying |
| 500 | `INTERNAL_ERROR` | Unexpected server error | Retry with exponential back-off; contact support if persistent |
| 503 | `VOICE_NOT_ENABLED` | Voice pipeline is not enabled on this deployment | Contact your Humain workspace admin |
| 503 | `PROVIDER_ERROR` | LLM or voice provider is temporarily unavailable | Retry with exponential back-off (1 s, 2 s, 4 s) |

> [!NOTE]
>
> `TURN_ERROR` and `SERVICE_UNAVAILABLE` are **not** HTTP status codes — they only appear as the
> `code` field of a WebSocket `error` frame during a text turn. See
> [Handling WebSocket errors](#handling-websocket-errors-conversation-turns) below.

## Codes with structured details

### `CREDENTIAL_BLOCKED` — 403

FraudGuard blocked this credential due to suspicious activity. The `details` object includes a
`blocked_until` timestamp indicating when the block automatically expires.

```json theme={null}
{
  "error": "CREDENTIAL_BLOCKED",
  "message": "This credential has been blocked due to suspicious activity.",
  "details": {
    "blocked_until": "2026-05-24T15:30:00Z",
    "reason": "Excessive rate-limit violations"
  }
}
```

Do not retry until after `blocked_until`. If the block appears incorrectly applied, contact
[support@humain.ai](mailto:support@humain.ai) with the credential label.

### `INPUT_REJECTED` — 400

The user's input was blocked before reaching the LLM. Check `details.reason` to understand why.

```json theme={null}
{
  "error": "INPUT_REJECTED",
  "message": "Input was rejected by a content rule.",
  "details": {
    "reason": "Contains a blocked phrase."
  }
}
```

Do not surface `reason` directly to end users — it may expose internal rule configuration.

### `RATE_LIMITED` — 429

The device has exceeded its allowed request rate. Back off for `details.retry_after_seconds`
before retrying.

```json theme={null}
{
  "error": "RATE_LIMITED",
  "message": "Rate limit exceeded.",
  "details": {
    "retry_after_seconds": 30
  }
}
```

### `VALIDATION_ERROR` — 422

The request body did not match the expected schema. `details` is a map of field names to error
messages.

```json theme={null}
{
  "error": "VALIDATION_ERROR",
  "message": "Request body failed validation.",
  "details": {
    "mode": "must be one of: text, voice, voip"
  }
}
```

## Handling HTTP errors (session open/end)

`POST /v1/sessions` and `POST {agent_url}/v1/sessions/{sid}/end` use the standard error
envelope above. Text conversation turns run over a WebSocket, not HTTP — see
[WebSocket streaming](https://humain.mintlify.site/connections/websocket-streaming.md#error-frames) for how errors surface
there instead (a `{"type":"error",...}` frame on the same connection, not an HTTP status code).

```javascript JavaScript theme={null}
const response = await fetch(`${BASE_URL}/v1/sessions`, {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${token}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ mode: 'text' }),
});

if (!response.ok) {
  const err = await response.json();

  switch (err.error) {
    case 'RATE_LIMITED':
      const retryAfter = err.details?.retry_after_seconds ?? 5;
      await sleep(retryAfter * 1000);
      return retry();

    case 'PLAN_LIMIT_REACHED':
      showUserMessage('This kiosk has reached its plan limit.');
      return;

    default:
      console.error('Humain API error', err);
      throw new Error(err.message);
  }
}
```

```python Python theme={null}
import httpx
import time

def open_session(*, retries: int = 3):
    for attempt in range(retries):
        resp = client.post("/v1/sessions", json={"mode": "text"})

        if resp.status_code == 201:
            return resp.json()

        err = resp.json()
        code = err.get("error")

        if code == "RATE_LIMITED":
            wait = err.get("details", {}).get("retry_after_seconds", 5)
            time.sleep(wait)
            continue

        if code == "PROVIDER_ERROR" and attempt < retries - 1:
            time.sleep(2 ** attempt)
            continue

        raise RuntimeError(f"Humain API error [{code}]: {err['message']}")
```

## Handling WebSocket errors (conversation turns)

Errors during a turn arrive as a JSON frame on the open connection with `code: "TURN_ERROR"` —
the real machine-readable reason is the `SCREAMING_SNAKE_CASE` prefix of `message`, before the
first `: `.

```javascript theme={null}
ws.onmessage = (event) => {
  const frame = JSON.parse(event.data);

  if (frame.type === 'error') {
    if (frame.code === 'SESSION_ENDED') {
      openNewSession();
      return;
    }
    // TURN_ERROR wraps the real reason as a "REASON_CODE: message" prefix
    const reason = frame.message?.split(':')[0];
    switch (reason) {
      case 'INPUT_REJECTED':
        showUserMessage('I cannot help with that request.');
        return;
      case 'RATE_LIMITED':
        showUserMessage('Please slow down and try again shortly.');
        return;
      case 'PROVIDER_ERROR':
        showUserMessage('AI is temporarily unavailable. Please try again in a moment.');
        return;
      default:
        console.error('Humain turn error', frame.message);
    }
  }
};
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.