Skip to main content

POST /ask/stream (streaming)

Send a chat message and receive the response as a Server-Sent Events (SSE) stream. Use this for real-time, token-by-token output.

Request

Method: POST
Path: /ask/stream
Headers:

  • Authorization: Bearer <api_key>
  • Content-Type: application/json

Body: Same as the non-streaming endpoint.

FieldTypeRequiredDescription
messagestringYesThe user message.
historyarrayNoPrevious messages (default: []).
conversationIdstringNoContinue an existing conversation.

Example:

{
"message": "Tell me a short story",
"history": [],
"conversationId": "abc123"
}

Response

The response is a Server-Sent Events stream. Each event is a line starting with data:.

Content deltas (text chunks):

data: {"type":"content","index":0,"delta":{"type":"text_delta","text":"Once"}}

data: {"type":"content","index":0,"delta":{"type":"text_delta","text":" upon"}}

data: {"type":"content","index":0,"delta":{"type":"text_delta","text":" a"}}

...

End of stream:

data: [DONE]

Parse each data: line as JSON (except [DONE]) and concatenate delta.text for the full reply.

cURL example

curl -X POST https://api.nyor.fun/ask/stream \
-H "Authorization: Bearer sk_live_YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"message": "Tell me a short story",
"history": [],
"conversationId": "abc123"
}'

Use a client that supports SSE (e.g. EventSource in browser, or a streaming HTTP client in Node.js). Plain cURL will print the raw stream.

Errors

If the request is invalid or the API key is wrong, you may receive a JSON error body before the stream starts, or the stream may end with an error. Check for 401 (invalid key) and 403 (rate limit). See Errors and rate limits.