---
title: "Invoke a function and stream the response (SSE or chunked)."
method: POST
path: "/functions/{id}/invoke-stream"
tags: ["invoke"]
---

# Invoke a function and stream the response (SSE or chunked).

`POST /functions/{id}/invoke-stream`

Streaming counterpart of `/functions/{id}/invoke`. The response
shape is selected from the request's `Accept` header:

* `Accept: text/event-stream` — Server-Sent Events. Each chunk
  the guest emits via the `wasi:tensor/host.emit-chunk` host
  function is rendered as one `event: chunk` frame. The stream
  terminates with an `event: done` frame on success or an
  `event: error` frame on guest failure / deadline-elapsed.
* Otherwise — `Content-Type: application/octet-stream`,
  `Transfer-Encoding: chunked`. Each guest chunk is forwarded
  verbatim as one HTTP chunk frame, followed by the same
  terminal `event: done` / `event: error` line so clients on
  either negotiation outcome detect end-of-stream uniformly.

### v0.4 wiring (T34)

The route is wired end-to-end through
`tensor_wasm_wasi_gpu::StreamingContext`. Guest emits land on a
`tokio::sync::mpsc::Receiver<Vec<u8>>` the gateway drains into
the response body. The cooperative-deadline path (T36) routes
a deadline-elapsed signal into a final `event: error` with
`{"reason":"deadline_elapsed"}` so SSE clients can distinguish
it from a generic trap. See `docs/STREAMING.md`.

## Path parameters

- `id` string, uuid, required

## Headers

- `X-TensorWasm-Tenant` integer
- `Accept` string

## Request body

- object — Arbitrary JSON payload, same shape as the synchronous invoke endpoint. The v0.x executor ignores the value.

## Response `200`

Streaming response. The body framing depends on the
negotiated content type — see the operation summary.

## Other responses

- `400` — Validation failure
- `401` — Missing or unrecognised bearer token
- `403` — Bearer token is not scoped to the requested tenant
- `404` — Function or job id is unknown
- `413` — Request body exceeded the 64 MiB cap enforced by axum's `DefaultBodyLimit::max`. Often rendered as a bare 413 with no body when the limit is hit during streaming.
- `429` — Per-token QPS + burst exceeded. The `Retry-After` header carries the wait in integer seconds (RFC 9110 §10.2.3).

---

[API](https://skmtc.dev/craton-co/apis/tensorwasm-http-api.md) · [All operations](https://skmtc.dev/craton-co/apis/tensorwasm-http-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/craton-co/tensorwasm-http-api/revisions/d363e13d8640/schema)
