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

# HTTP API

> Call Waniwani from any language over HTTPS: base URLs, keys, request and response shapes, errors, and a complete example that sends events.

Everything the Waniwani SDK and chat widget do goes through a JSON API over HTTPS, and you can call it yourself from any language. This page covers what every route has in common, then sends events end to end. The **Server API** and **Chat API** sections list each route with its full request and response schema.

## Base URL

Use the URL of the region your organization was created in. A key from one region gets a `401` from the other.

| Region | Base URL |
| - | - |
| US | `https://app.waniwani.ai` |
| EU | `https://eu.app.waniwani.ai` |

## Authentication

Every request carries a key as a bearer token:

```http theme={null}
Authorization: Bearer wwk_...
```

| Key | Where it lives | Routes |
| - | - | - |
| API key, `wwk_...` | Your server. It is a secret. Each environment (Staging, Production) has its own, under **Settings > API Keys** on your agent's page. | Server API |
| Public key, `wwp_...` | A web page. It belongs to a chat channel and is safe to ship to browsers. | Chat API |

The events route takes either key. Data lands in the environment the key belongs to.

## Requests and responses

Send JSON with `Content-Type: application/json`. Each endpoint page shows its method, its fields and which of them are required.

Most routes answer inside an envelope, with the route's own result in `data`. Searching the knowledge base, for example:

```bash theme={null}
curl https://app.waniwani.ai/api/mcp/kb/search \
  -H "Authorization: Bearer $WANIWANI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "query": "Is water damage covered?", "topK": 3 }'
```

```json theme={null}
{
  "success": true,
  "message": "success",
  "data": [
    {
      "source": "home-policy.md",
      "heading": "Water damage",
      "content": "Damage from a sudden leak is covered up to...",
      "score": 0.82
    }
  ]
}
```

Three routes answer with their result directly, without the envelope: the events route (shown below) and the two WebMCP routes. Their endpoint pages show the exact body.

## Errors

A failed request answers with a 4xx or 5xx status. The body carries the error code in `error`, and `errorId` identifies the failure if you contact support:

```json theme={null}
{
  "success": false,
  "error": "INVALID_API_KEY",
  "code": "INVALID_API_KEY",
  "message": "INVALID_API_KEY",
  "errorId": "3f9c2a1b"
}
```

The events route answers errors as `{ "error": "INVALID_API_KEY", "requestId": "ingest_req_..." }`.

| Status | What to do |
| - | - |
| `408`, `425`, `429`, `5xx` | Send the same request again after a backoff. The SDK waits longer after each try. |
| Any other `4xx` | Fix the request. Sent again unchanged, it fails the same way. |

## Send events

`POST /api/mcp/events/v2/batch` takes a batch of events and stores each one that passes the checks. This is the route the SDK's `track()` calls.

```bash theme={null}
curl https://app.waniwani.ai/api/mcp/events/v2/batch \
  -H "Authorization: Bearer $WANIWANI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "sentAt": "2026-11-18T10:00:00.000Z",
    "source": { "sdk": "acme-ruby", "version": "1.0.0" },
    "events": [
      {
        "id": "evt_6f1c2a9e-1b7d-4c55-9a3e-2f0b8d4c1e77",
        "type": "mcp.event",
        "name": "lead_qualified",
        "timestamp": "2026-11-18T09:59:58.120Z",
        "correlation": { "sessionId": "sess_8d2f" },
        "properties": { "channelId": "<your channel id>", "email": "jane@acme.com" }
      }
    ]
  }'
```

```json theme={null}
{ "accepted": 1, "requestId": "ingest_req_..." }
```

### The batch

| Field | What to send |
| - | - |
| `sentAt` | When you sent the batch, as an ISO 8601 date-time. |
| `source.sdk`, `source.version` | Your client's name and version. Both are required. |
| `events[].id` | A unique id per event, such as `evt_` followed by a UUID. Keep it when you retry. |
| `events[].type` | Always `"mcp.event"`. |
| `events[].name` | An event name from the [event schema](https://docs.waniwani.ai/sdk/reference/event-schema.md#eventtype-union), such as `lead_qualified` or `link.clicked`. |
| `events[].timestamp` | When the event happened, as an ISO 8601 date-time. |
| `events[].correlation` | Who the event belongs to: at least one of `sessionId` (the conversation), `externalUserId` (your id for the person) or `visitorId` (an anonymous device id). |
| `events[].properties` | The event's [properties](https://docs.waniwani.ai/sdk/reference/event-schema.md#typed-property-interfaces), plus `channelId`. |
| `events[].source` | Optional. Where the event came from, such as `chatgpt`. |

Put your channel's id in `properties.channelId`. Waniwani files each event under a channel, and without an id it tries to match `source` to a channel's label. An event that matches no channel is rejected.

Neither the batch nor an event takes other keys. An unknown key in the batch fails the whole request with a `400`, and one in an event rejects that event alone.

### The response

Each event is checked on its own, so a `200` can list events that were not stored:

```json theme={null}
{
  "accepted": 1,
  "rejected": [
    {
      "eventId": "evt_0b7e...",
      "code": "validation_failed",
      "message": "event must include a session_id, external_user_id, or visitor_id",
      "retryable": false
    }
  ],
  "requestId": "ingest_req_..."
}
```

`accepted` counts the events that passed. `rejected` lists the others and is absent when there are none. Send a rejected event again later when its `retryable` is `true`. When it is `false`, fix the event first.

| Status | Meaning |
| - | - |
| `200` | The batch was read. Check `rejected`. |
| `400` | The body is not valid JSON or not a valid batch. `details` lists the problems. |
| `401` | The key is missing, not valid, or from the other region. |
| `403` | The public key cannot send events from this origin. |
| `410` | The environment is archived. |

### Retries

Waniwani stores an event id once. When a request times out and you can't tell whether it arrived, send the same batch again with the same ids, and the events already stored are skipped. They still count in `accepted`, so count delivered events by their ids, not by adding up `accepted`.

The SDK sends up to 20 events per batch.


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