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

# POST /v1/ask/stream

> The streaming variant of /v1/ask — first tokens in about five seconds instead of waiting for the whole answer.

Same request body as [`POST /v1/ask`](/api-reference/ask), same credit cost,
same planner and synthesizer. The difference is delivery: the answer arrives
as Server-Sent Events while it is being written, so a chat UI can render the
first sentence at around five to seven seconds instead of sitting on a
spinner for the full synthesis.

Use the buffered route for pipelines and batch jobs. Use this one whenever a
person is watching.

## Frames

| Event   | Payload                                 | When                                          |
| ------- | --------------------------------------- | --------------------------------------------- |
| `delta` | an incremental chunk of the answer text | repeatedly, as the synthesizer writes         |
| `final` | the complete `/v1/ask` response body    | once, terminal                                |
| `error` | an error object                         | once, terminal, if synthesis fails mid-stream |

<Warning>
  A terminal `error` frame means there is **no** `final` frame coming. Discard
  any `delta` text you have already accumulated rather than presenting it as the
  answer — a mid-stream `ask_answer_incomplete` means the model was cut off, so
  the text on the wire is a fragment, not a short answer. The credits for that
  request are refunded, best-effort.
</Warning>

The `final` frame is the one to trust. It carries the full body — `answer`,
`confidence`, `citations`, `fields_used` — identical to what the buffered
endpoint would have returned. **Do not assemble your citations from `delta`
frames**; concatenated deltas give you the prose, not the audit trail.

## Call it

```bash theme={null}
curl -N -s https://api.mireye.com/v1/ask/stream \
  -H "Authorization: Bearer $MIREYE_API_TOKEN" \
  -H 'content-type: application/json' \
  -H 'accept: text/event-stream' \
  -d '{
    "lat": 32.7767,
    "lng": -96.7970,
    "question": "What transmission infrastructure is near this site?"
  }'
```

```text theme={null}
event: delta
data: {"text":"The nearest transmission"}

event: delta
data: {"text":" infrastructure is a 138 kV"}

...

event: final
data: {"answer":"...","confidence":"high","citations":[...],"fields_used":[...]}
```

## Failure modes

A failure **before the first byte** surfaces as a real HTTP status — a `429`
with `Retry-After` under `ask_busy` back-pressure, or a `4xx`/`5xx` from
[Errors](/api-reference/errors). Your normal error handling catches it.

A failure **after** the stream has opened cannot change the status code, so
it arrives as a terminal `error` frame on a connection that already returned
`200`. Treat a stream that ends without a `final` frame as a failure, not as
a short answer.

Both routes share the same 110-second deadline.


## OpenAPI

````yaml POST /v1/ask/stream
openapi: 3.1.0
info:
  title: Mireye Earth
  description: >-
    Provenance-tagged geospatial data for US coordinates. POST /v1/fetch for
    deterministic field values (POST /v1/fetch/batch for up to 25 locations at
    once); POST /v1/ask for natural-language Q&A; GET /v1/meta/fields for the
    catalog.
  version: 0.16.0
servers: []
security: []
paths:
  /v1/ask/stream:
    post:
      summary: Streaming (SSE) natural-language Q&A over a US coordinate
      description: >-
        Server-Sent Events variant of `/v1/ask`, same request body. Emits
        `delta` frames as the answer is synthesized (first tokens ~5-7 s), then
        one terminal `final` frame carrying the full `/v1/ask` body, or an
        `error` frame on mid-stream failure. Same 110 s deadline and `429
        ask_busy` back-pressure as the buffered route; failures before the first
        byte surface as a real HTTP status (with `Retry-After` when retryable).
        Set a client timeout of at least 120 s.
      operationId: ask_stream_v1_ask_stream_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AskRequest'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema: {}
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    AskRequest:
      properties:
        lat:
          anyOf:
            - type: number
            - type: 'null'
          title: Lat
        lng:
          anyOf:
            - type: number
            - type: 'null'
          title: Lng
        address:
          anyOf:
            - type: string
              maxLength: 256
              minLength: 1
            - type: 'null'
          title: Address
        question:
          type: string
          maxLength: 2000
          minLength: 1
          title: Question
        include_trace:
          type: boolean
          title: Include Trace
          default: false
      type: object
      required:
        - question
      title: AskRequest
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError

````