Skip to content
Skip to Content
DevelopersAPI referenceAI

Ask a question about your saved items

POST
/v1/chat

Ask questions about the caller's own saved items. By default each request is stateless: send the conversation so far (at most 20 messages of up to 4000 characters, ending with a user message) and get the next answer.

Chat memory (only when the server runs with CHAT_MEMORY=true; the answer then carries conversation_id). The first turn starts a saved conversation. Send its conversation_id with later turns and only the new user message: the server uses the stored messages as the history and ignores any earlier ones sent. A conversation lasts one day from its first message, then it can no longer be read or continued (404 chat.conversation_not_found) and is deleted. It holds at most 100 messages (409 chat.conversation_full).

Each turn turns the latest message into a search query, searches the caller's items (never other people's, not even items shared with them), and answers only from the best matches, citing them as [n]. The answer comes back with the sources it cites.

A turn uses two model calls from the daily AI allowance (one when nothing matches). Errors: 503 when the server has no AI model, 429 when today's allowance (it resets at midnight UTC) or the hourly chat limit is used up, and 502 when the model fails or returns something unusable. Saved pages are untrusted text, and the model gets them as data only.

Streaming. Send Accept: text/event-stream to get the turn as server-sent events instead of one JSON body:

  • query once, {"query": "..."}: the search being run, as soon as it is known.
  • delta any number of times, {"text": "..."}: the next piece of the answer. Citations to items that do not exist are already removed, and a half-written [12 is held back until it is checked.
  • done last, with the same ChatAnswer body as the JSON response. Replace the streamed text with its answer: it is trimmed and length-capped, so it can differ slightly from the joined pieces.
  • error instead of done if the turn fails after events began: {"error": {"status": 502, "type": "upstream_error", "message": "..."}}. Pieces already shown were real answer text, but the answer is incomplete.

Anything refused before the first event (validation, plan, allowance, rate limit, AI off) is the usual JSON error with its status code. The cost and limits are the same as a plain turn.

Authorization

bearer
headerAuthorizationBearer <token>

A personal API key (ga_…), sent as Authorization: Bearer ga_…. A key gets 403 on a resource it has no access to, and on anything that changes data without write access.

Request Body

application/json
  1. body
conversation_id?string

Continue this saved conversation (chat memory only). Omit to start one.

messages*array<>
Items1 <= items <= 20

Response Body

The answer and the items it cites

  1. response
answer*string

Plain text, with citations like [1]

query*string

The search that was run for this turn

sources*array<>

Only the items the answer cites, in order

conversation_id?string

The saved conversation this turn belongs to. Only with chat memory on.

Example Request
curl -X POST 'https://example.com/v1/chat' \  -H 'Content-Type: application/json' \  -d '{  "messages": [    {      "role": "user",      "content": "string"    }  ]}'
Example Response
{  "answer": "string",  "query": "string",  "sources": [    {      "n": 0,      "id": "string",      "kind": "link",      "title": "string",      "url": "string",      "domain": "string"    }  ],  "conversation_id": "string"}