Streaming (SSE) natural-language Q&A over a US coordinate
curl --request POST \
--url https://api.example.com/v1/ask/stream \
--header 'Content-Type: application/json' \
--data '
{
"question": "<string>",
"lat": 123,
"lng": 123,
"address": "<string>",
"include_trace": false
}
'import requests
url = "https://api.example.com/v1/ask/stream"
payload = {
"question": "<string>",
"lat": 123,
"lng": 123,
"address": "<string>",
"include_trace": False
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
question: '<string>',
lat: 123,
lng: 123,
address: '<string>',
include_trace: false
})
};
fetch('https://api.example.com/v1/ask/stream', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/v1/ask/stream",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'question' => '<string>',
'lat' => 123,
'lng' => 123,
'address' => '<string>',
'include_trace' => false
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/v1/ask/stream"
payload := strings.NewReader("{\n \"question\": \"<string>\",\n \"lat\": 123,\n \"lng\": 123,\n \"address\": \"<string>\",\n \"include_trace\": false\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/v1/ask/stream")
.header("Content-Type", "application/json")
.body("{\n \"question\": \"<string>\",\n \"lat\": 123,\n \"lng\": 123,\n \"address\": \"<string>\",\n \"include_trace\": false\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/v1/ask/stream")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"question\": \"<string>\",\n \"lat\": 123,\n \"lng\": 123,\n \"address\": \"<string>\",\n \"include_trace\": false\n}"
response = http.request(request)
puts response.read_body{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>",
"input": "<unknown>",
"ctx": {}
}
]
}Ask
POST /v1/ask/stream
The streaming variant of /v1/ask — first tokens in about five seconds instead of waiting for the whole answer.
POST
/
v1
/
ask
/
stream
Streaming (SSE) natural-language Q&A over a US coordinate
curl --request POST \
--url https://api.example.com/v1/ask/stream \
--header 'Content-Type: application/json' \
--data '
{
"question": "<string>",
"lat": 123,
"lng": 123,
"address": "<string>",
"include_trace": false
}
'import requests
url = "https://api.example.com/v1/ask/stream"
payload = {
"question": "<string>",
"lat": 123,
"lng": 123,
"address": "<string>",
"include_trace": False
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
question: '<string>',
lat: 123,
lng: 123,
address: '<string>',
include_trace: false
})
};
fetch('https://api.example.com/v1/ask/stream', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/v1/ask/stream",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'question' => '<string>',
'lat' => 123,
'lng' => 123,
'address' => '<string>',
'include_trace' => false
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/v1/ask/stream"
payload := strings.NewReader("{\n \"question\": \"<string>\",\n \"lat\": 123,\n \"lng\": 123,\n \"address\": \"<string>\",\n \"include_trace\": false\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/v1/ask/stream")
.header("Content-Type", "application/json")
.body("{\n \"question\": \"<string>\",\n \"lat\": 123,\n \"lng\": 123,\n \"address\": \"<string>\",\n \"include_trace\": false\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/v1/ask/stream")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"question\": \"<string>\",\n \"lat\": 123,\n \"lng\": 123,\n \"address\": \"<string>\",\n \"include_trace\": false\n}"
response = http.request(request)
puts response.read_body{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>",
"input": "<unknown>",
"ctx": {}
}
]
}Same request body as
The
POST /v1/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 |
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.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
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?"
}'
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 — a429
with Retry-After under ask_busy back-pressure, or a 4xx/5xx from
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.