Answer a run with a stream that reaches your caller as it is written, and report the outcome.
An agent can answer POST /invoke with a stream instead of JSON: a Vercel AI SDK UI message stream, AG-UI, server-sent events, NDJSON, plain text — any format. A caller who started the run with ?passthrough=true receives it byte for byte as you write it, so a chat UI can read your agent’s own stream format with no mapping in between.
Post the same JSON you would have answered, with the run token:
POST {api_url}/v0/runs/{run_id}/resultx-agentos-run-token: <context.token>{"status": "completed", "output": {"text": "..."}}
It answers 202 {"status": "accepted"}. The body is one of:
{"status": "completed", "output": {...}} — the output is checked against the capability’s output schema at once; a mismatch answers 422 invalid_output with errors, so you can correct it and post again;
{"status": "suspended", "hold_id": "h_7"} — after asking a person.
A result is at most 1 MiB and is accepted once per invocation: the same result again is accepted too, a different one is 409 result_already_reported. It is scrubbed of secrets like a JSON answer, and recorded when the stream ends.
Post the result before your stream ends, or at the latest within 3 seconds of its end. A later one is refused with 401: the invocation’s token has ended.
Return a stream and set the output; the SDK posts the result for you before the stream ends:
import agentosdef tell(inv: agentos.Invocation): def pieces(): text = "" for delta in inv.llm.stream([{"role": "user", "content": inv.input["topic"]}]): text += delta yield delta inv.set_output({"text": text}) # reported as the run's output return agentos.Stream(pieces(), "text/plain; charset=utf-8")agentos.serve({"tell": tell}, port=8080)
import { serve, stream } from "@agentos/sdk";await serve({ tell(inv) { return stream((async function* () { let text = ""; for await (const delta of inv.llm.stream([{ role: "user", content: inv.input.topic }])) { text += delta; yield delta; } inv.setOutput({ text }); // reported as the run's output })(), { contentType: "text/plain; charset=utf-8" }); },}, { port: 8080 });
If the platform refuses the result (an output that doesn’t match the schema), the SDK reports failed instead, so a run never completes silently with a bad output. A caller that goes away ends the stream and fails the run.
If no result arrives, AgentOS waits those 3 seconds after the stream ends, then decides:
A 2xx body of at most 1 MiB that is the contract’s JSON ({"status": "completed" | "failed" | "suspended", ...}) but sent with another Content-Type — some frameworks send JSON as text/html — is read as the contract, at once.
A stream that ended cleanly with a 2xx status holds the run if this invocation asked a person, and otherwise completes it with output: {"streamed": true, "bytes": ..., "content_type": "..."}. That output isn’t checked against the output schema, and the run page marks the run “streamed”.
Anything else fails the run with agent_interrupted, a non-2xx error page included.
To ask a person in the middle of a stream: create the hold, end your stream the way your format ends it, and report {"status": "suspended", "hold_id": "h_7"}. The resume that follows the decision isn’t streamed to anyone; answer it with JSON, or with a stream and a result, and callers read its output from the run.
What you stream reaches the caller exactly as you wrote it. Unlike the output, error and events AgentOS stores, a stream is not scrubbed of secrets. Never write context.token, a secret or the invoke body into it.
Start the run with ?passthrough=true. The response is exactly what the agent answered — its status code, Content-Type, and body as it arrives — plus an X-AgentOS-Run-Id header:
A chat app’s backend calls this with its API key and hands the response to the browser unchanged, so a UI built on the AI SDK’s useChat, for example, reads it directly. Never put an API key in a browser. Closing the connection doesn’t stop the run; cancel it. After the stream, GET the run for its outcome. See the Runs API for headers, replays and limits.
examples/stream-agent streams a model’s answer as a Vercel AI SDK UI message stream, asks a person mid-stream, and turns a guardrail block into a clean failed run. See Examples.
{"docsConfig":{"theme":"aspen","$schema":"https://mintlify.com/docs.json","name":"Upsonic AI","colors":{"primary":"#03D47E","light":"#00D37F","dark":"#00D37F"},"logo":{"light":"https://mintcdn.com/upsonic/eD3pOHUjFRrpRlr1/logo/logo_name.png?fit=max\u0026auto=format\u0026n=eD3pOHUjFRrpRlr1\u0026q=85\u0026s=a5f719ba8cc7e2e5247f98ce0f4cd570","dark":"https://mintcdn.com/upsonic/NvtIPMvILtME55zd/logo/logo_name_dark.png?fit=max\u0026auto=format\u0026n=NvtIPMvILtME55zd\u0026q=85\u0026s=b6ee805d29e1196fd56206200f0fe42b"},"favicon":"https://mintcdn.com/upsonic/Q5tER9e3gIUsdKBE/favicon.png?fit=max\u0026auto=format\u0026n=Q5tER9e3gIUsdKBE\u0026q=85\u0026s=6d90389a3780b1c15cff5e3f56f8bd5b","appearance":{"default":"dark","strict":false},"navbar":{"primary":{"type":"github","href":"https://github.com/Upsonic/Upsonic"}},"footer":{"socials":{"discord":"https://discord.gg/7648R8JahY","x":"https://x.com/UpsonicAI","github":"https://github.com/Upsonic","linkedin":"https://www.linkedin.com/company/getupsonic"}},"fonts":{"heading":{"family":"Helvetica","weight":750},"body":{"family":"Inter","weight":400}},"integrations":{"gtm":{"tagId":"GTM-MQ8VVXSB"}},"interaction":{"drilldown":true},"styling":{"latex":true},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"upsonic","hasAudioNarration":false,"actualSubdomain":"upsonic","customDomains":["docs.upsonic.ai"],"gitSource":{"type":"github","owner":"upsonic","repo":"docs","deployBranch":"main","contentDirectory":"","isPrivate":true,"mountPath":"","label":""},"chroma":{"liveDeploymentHistoryId":"6a21f60ca51a213e6e8ae5f7","collectionId":"71a50b3a-7bd7-4713-9f3f-5bb7d45db5f7","schemaVersion":"v2"},"entitlements":{},"buildId":"6ae0964beb5b4f30de3efad5","clientVersion":"0.0.3971","searchFilterCounts":[{"language":"default","tag":"Upsonic Framework","count":373},{"language":"default","tag":"CONCEPTS","count":353},{"language":"default","tag":"Usage","count":109},{"language":"default","tag":"Advanced","count":79},{"language":"default","tag":"Tools","count":52},{"language":"default","tag":"Knowledge Base","count":51},{"language":"default","tag":"Integrations","count":45},{"language":"default","tag":"LLM Support","count":32},{"language":"default","tag":"Examples","count":31},{"language":"default","tag":"Agent","count":22}]},"assistantConfig":{},"basePath":"","hasChatPermissions":false,"hasWebMcpPermissions":false,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-v7-file-tree","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-onboarding","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"pause-universal-search-reconcile","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"per-site-search-delta","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-private-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-nav-generations","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"assistant-v5","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"byok-sep-25","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"vite-origin","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-agent-model-picker","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-updated-9-15","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-sso-scim","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-signup","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-enabled","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"isAtlas":false,"googleFontsInlined":false},"customCss":[],"page":{"pagePath":"agentos/build/streaming","slug":"/agentos/build/streaming","pageMetadata":{"title":"Streaming answers","description":"Answer a run with a stream that reaches your caller as it is written, and report the outcome.","href":"/agentos/build/streaming"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"Answer a run with a stream that reaches your caller as it is written, and report the outcome.\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={a:`a`,code:`code`,li:`li`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,ul:`ul`,..._provideComponents(),...props.components},{CodeBlock,CodeGroup,Heading,Tip,Warning}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!CodeGroup)_missingMdxReference(`CodeGroup`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Tip)_missingMdxReference(`Tip`,true);if(!Warning)_missingMdxReference(`Warning`,true);return _jsxs(_Fragment,{children:[_jsxs(_components.p,{children:[`An agent can answer `,_jsx(_components.code,{children:`POST /invoke`}),` with a stream instead of JSON: a Vercel AI SDK UI message stream, AG-UI, server-sent events, NDJSON, plain text — any format. A caller who started the run with `,_jsx(_components.code,{children:`?passthrough=true`}),` receives it byte for byte as you write it, so a chat UI can read your agent’s own stream format with no mapping in between.`]}),`\n`,_jsx(Heading,{level:`2`,id:`how-agentos-tells-json-from-a-stream`,children:`How AgentOS tells JSON from a stream`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[`An answer whose `,_jsx(_components.code,{children:`Content-Type`}),` is `,_jsx(_components.code,{children:`application/json`}),` (or that has none) is the `,_jsx(_components.a,{href:`/agentos/build/agent-contract#answering`,children:`contract’s JSON`}),`.`]}),`\n`,_jsxs(_components.li,{children:[`Any other `,_jsx(_components.code,{children:`Content-Type`}),` is a stream. AgentOS doesn’t read into it; it relays it to a passthrough caller.`]}),`\n`]}),`\n`,_jsxs(_components.p,{children:[`Because AgentOS doesn’t read your stream, `,_jsx(_components.strong,{children:`your agent reports the run’s outcome itself`}),`, before the stream ends.`]}),`\n`,_jsx(Heading,{level:`2`,id:`report-the-result`,children:`Report the result`}),`\n`,_jsx(_components.p,{children:`Post the same JSON you would have answered, with the run token:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`4`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`4`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`POST`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` {api_url}/v0/runs/{run_id}/result`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`x-agentos-run-token:`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` \u003c`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`context.toke`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`n`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`>`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`\"status\"`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"completed\",`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"output\":`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` {\"text\":`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"...\"}}`})]}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`It answers `,_jsx(_components.code,{children:`202 {\"status\": \"accepted\"}`}),`. The body is one of:`]}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`{\"status\": \"completed\", \"output\": {...}}`}),` — the output is checked against the capability’s `,_jsx(_components.code,{children:`output`}),` schema at once; a mismatch answers `,_jsx(_components.code,{children:`422 invalid_output`}),` with `,_jsx(_components.code,{children:`errors`}),`, so you can correct it and post again;`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`{\"status\": \"failed\", \"error\": {\"code\": \"...\", \"message\": \"...\"}}`}),`;`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`{\"status\": \"suspended\", \"hold_id\": \"h_7\"}`}),` — after `,_jsx(_components.a,{href:`#asking-a-person-mid-stream`,children:`asking a person`}),`.`]}),`\n`]}),`\n`,_jsxs(_components.p,{children:[`A result is at most 1 MiB and is accepted once per invocation: the same result again is accepted too, a different one is `,_jsx(_components.code,{children:`409 result_already_reported`}),`. It is scrubbed of secrets like a JSON answer, and recorded when the stream ends.`]}),`\n`,_jsx(Warning,{children:_jsxs(_components.p,{children:[`Post the result `,_jsx(_components.strong,{children:`before your stream ends`}),`, or at the latest within 3 seconds of its end. A later one is refused with `,_jsx(_components.code,{children:`401`}),`: the invocation’s token has ended.`]})}),`\n`,_jsx(Heading,{level:`2`,id:`with-the-sdks`,children:`With the SDKs`}),`\n`,_jsx(_components.p,{children:`Return a stream and set the output; the SDK posts the result for you before the stream ends:`}),`\n`,_jsxs(CodeGroup,{children:[_jsx(CodeBlock,{filename:`Python`,numberOfLines:`13`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`13`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` agentos`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`def`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` tell`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`inv`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: agentos.Invocation):`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` def`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` pieces`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`():`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` text `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"\"`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` delta `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` inv.llm.stream([{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"role\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"user\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"content\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: inv.input[`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"topic\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`]}]):`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` text `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`+=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` delta`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` yield`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` delta`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` inv.set_output({`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"text\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: text}) `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# reported as the run's output`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` return`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` agentos.Stream(pieces(), `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"text/plain; charset=utf-8\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`agentos.serve({`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"tell\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: tell}, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`port`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`8080`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`]})})}),_jsx(CodeBlock,{filename:`TypeScript`,numberOfLines:`14`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`14`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`serve`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`stream`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"@agentos/sdk\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`await`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` serve`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` tell`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`inv`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` return`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` stream`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`((`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`async`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` function*`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` () {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` let`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` text`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` for`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` delta`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` of`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` inv`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`llm`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`stream`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`([{ `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`role:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"user\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` inv`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`input`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`topic`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }])) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` text`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` +=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` delta`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` yield`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` delta`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` inv`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`setOutput`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({ `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`text`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }); `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// reported as the run's output`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` })(), { `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`contentType:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"text/plain; charset=utf-8\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` });`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` },`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}, { `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`port:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 8080`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` });`})]}),`\n`]})})})]}),`\n`,_jsxs(_components.p,{children:[`If the platform refuses the result (an output that doesn’t match the schema), the SDK reports `,_jsx(_components.code,{children:`failed`}),` instead, so a run never completes silently with a bad output. A caller that goes away ends the stream and fails the run.`]}),`\n`,_jsx(Heading,{level:`2`,id:`without-a-result`,children:`Without a result`}),`\n`,_jsx(_components.p,{children:`If no result arrives, AgentOS waits those 3 seconds after the stream ends, then decides:`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[`A `,_jsx(_components.code,{children:`2xx`}),` body of at most 1 MiB that is the contract’s JSON (`,_jsx(_components.code,{children:`{\"status\": \"completed\" | \"failed\" | \"suspended\", ...}`}),`) but sent with another `,_jsx(_components.code,{children:`Content-Type`}),` — some frameworks send JSON as `,_jsx(_components.code,{children:`text/html`}),` — is read as the contract, at once.`]}),`\n`,_jsxs(_components.li,{children:[`A stream that ended cleanly with a `,_jsx(_components.code,{children:`2xx`}),` status `,_jsx(_components.strong,{children:`holds`}),` the run if this invocation asked a person, and otherwise `,_jsx(_components.strong,{children:`completes`}),` it with `,_jsx(_components.code,{children:`output: {\"streamed\": true, \"bytes\": ..., \"content_type\": \"...\"}`}),`. That output isn’t checked against the output schema, and the run page marks the run “streamed”.`]}),`\n`,_jsxs(_components.li,{children:[`Anything else fails the run with `,_jsx(_components.code,{children:`agent_interrupted`}),`, a non-`,_jsx(_components.code,{children:`2xx`}),` error page included.`]}),`\n`]}),`\n`,_jsx(Heading,{level:`2`,id:`limits`,children:`Limits`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[`A stream may pause up to the capability’s `,_jsx(_components.code,{children:`timeout`}),` between writes.`]}),`\n`,_jsxs(_components.li,{children:[`A stream may be at most 10 MiB; more fails the run with `,_jsx(_components.code,{children:`invalid_response`}),`.`]}),`\n`]}),`\n`,_jsx(Heading,{level:`2`,id:`asking-a-person-mid-stream`,children:`Asking a person mid-stream`}),`\n`,_jsxs(_components.p,{children:[`To `,_jsx(_components.a,{href:`/agentos/build/human-approvals`,children:`ask a person`}),` in the middle of a stream: create the hold, end your stream the way your format ends it, and report `,_jsx(_components.code,{children:`{\"status\": \"suspended\", \"hold_id\": \"h_7\"}`}),`. The resume that follows the decision isn’t streamed to anyone; answer it with JSON, or with a stream and a result, and callers read its output from the run.`]}),`\n`,_jsx(Heading,{level:`2`,id:`never-stream-secrets`,children:`Never stream secrets`}),`\n`,_jsx(Warning,{children:_jsxs(_components.p,{children:[`What you stream reaches the caller exactly as you wrote it. Unlike the output, error and events AgentOS stores, `,_jsx(_components.strong,{children:`a stream is not scrubbed`}),` of secrets. Never write `,_jsx(_components.code,{children:`context.token`}),`, a secret or the invoke body into it.`]})}),`\n`,_jsx(Heading,{level:`2`,id:`reading-the-stream-as-a-caller`,children:`Reading the stream as a caller`}),`\n`,_jsxs(_components.p,{children:[`Start the run with `,_jsx(_components.code,{children:`?passthrough=true`}),`. The response is exactly what the agent answered — its status code, `,_jsx(_components.code,{children:`Content-Type`}),`, and body as it arrives — plus an `,_jsx(_components.code,{children:`X-AgentOS-Run-Id`}),` header:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`3`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`3`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`curl`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -sS`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -N`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -D`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` -`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -X`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` POST`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`$AGENTOS`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`/v0/envs/default/agents/stream-agent/capabilities/chat/runs?passthrough=true\"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -H`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Authorization: Bearer `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`$AGENTOS_API_KEY`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -H`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Content-Type: application/json\"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -d`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '{\"input\": {\"message\": \"What is AgentOS?\"}}'`})]}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`A chat app’s backend calls this with its API key and hands the response to the browser unchanged, so a UI built on the AI SDK’s `,_jsx(_components.code,{children:`useChat`}),`, for example, reads it directly. Never put an API key in a browser. Closing the connection doesn’t stop the run; cancel it. After the stream, `,_jsx(_components.code,{children:`GET`}),` the run for its outcome. See the `,_jsx(_components.a,{href:`/agentos/api/runs`,children:`Runs API`}),` for headers, replays and limits.`]}),`\n`,_jsx(Tip,{children:_jsxs(_components.p,{children:[_jsx(_components.code,{children:`examples/stream-agent`}),` streams a model’s answer as a Vercel AI SDK UI message stream, asks a person mid-stream, and turns a guardrail block into a clean `,_jsx(_components.code,{children:`failed`}),` run. See `,_jsx(_components.a,{href:`/agentos/build/examples`,children:`Examples`}),`.`]})})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"config":{},"pageMetadata":{"title":"Streaming answers","description":"Answer a run with a stream that reaches your caller as it is written, and report the outcome.","href":"/agentos/build/streaming"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"How AgentOS tells JSON from a stream","slug":"how-agentos-tells-json-from-a-stream","depth":2,"children":[]},{"title":"Report the result","slug":"report-the-result","depth":2,"children":[]},{"title":"With the SDKs","slug":"with-the-sdks","depth":2,"children":[]},{"title":"Without a result","slug":"without-a-result","depth":2,"children":[]},{"title":"Limits","slug":"limits","depth":2,"children":[]},{"title":"Asking a person mid-stream","slug":"asking-a-person-mid-stream","depth":2,"children":[]},{"title":"Never stream secrets","slug":"never-stream-secrets","depth":2,"children":[]},{"title":"Reading the stream as a caller","slug":"reading-the-stream-as-a-caller","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":["/_mintlify/custom/upsonic/418601343a17abbb/ga.js"],"subdomain":"upsonic","siteName":"Upsonic AI","title":"Streaming answers - Upsonic AI","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-10-27T12:17:32.038Z","originalFileLocation":"agentos/build/streaming.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"dark\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"Answer a run with a stream that reaches your caller as it is written, and report the outcome.\">\u003cmeta data-mint-head name=\"application-name\" content=\"Upsonic AI\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/upsonic/adDEYx-Qrl3jC12g/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/upsonic/adDEYx-Qrl3jC12g/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/upsonic/adDEYx-Qrl3jC12g/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/upsonic/adDEYx-Qrl3jC12g/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/upsonic/adDEYx-Qrl3jC12g/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/upsonic/adDEYx-Qrl3jC12g/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/upsonic/adDEYx-Qrl3jC12g/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/upsonic/adDEYx-Qrl3jC12g/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/upsonic/adDEYx-Qrl3jC12g/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Streaming answers - Upsonic AI\">\u003cmeta data-mint-head property=\"og:description\" content=\"Answer a run with a stream that reaches your caller as it is written, and report the outcome.\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"Upsonic AI\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://docs.upsonic.ai/agentos/build/streaming\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://upsonic.mintlify.app/_mintlify/api/og/v2?division=BUILD+AGENTS\u0026amp;title=Streaming+answers\u0026amp;description=Answer+a+run+with+a+stream+that+reaches+your+caller+as+it+is+written%2C+and+report+the+outcome.\u0026amp;theme=f10e740e935a15f993181be8\u0026amp;signature=fd916e74a617cb28ac90bfc3ef83dfc472396c7549ef41e108a8e8b83c3782dd\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"Streaming answers - Upsonic AI\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Answer a run with a stream that reaches your caller as it is written, and report the outcome.\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://upsonic.mintlify.app/_mintlify/api/og/v2?division=BUILD+AGENTS\u0026amp;title=Streaming+answers\u0026amp;description=Answer+a+run+with+a+stream+that+reaches+your+caller+as+it+is+written%2C+and+report+the+outcome.\u0026amp;theme=f10e740e935a15f993181be8\u0026amp;signature=fd916e74a617cb28ac90bfc3ef83dfc472396c7549ef41e108a8e8b83c3782dd\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/upsonic/adDEYx-Qrl3jC12g/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"Upsonic AI\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#03D47E\">\u003clink data-mint-head rel=\"canonical\" href=\"https://docs.upsonic.ai/agentos/build/streaming\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/agentos/build/streaming.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://docs.upsonic.ai/#organization\",\"name\":\"Upsonic AI\",\"url\":\"https://docs.upsonic.ai\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/upsonic/eD3pOHUjFRrpRlr1/logo/logo_name.png?fit=max\u0026auto=format\u0026n=eD3pOHUjFRrpRlr1\u0026q=85\u0026s=a5f719ba8cc7e2e5247f98ce0f4cd570\"}},{\"@type\":\"WebSite\",\"@id\":\"https://docs.upsonic.ai#website\",\"name\":\"Upsonic AI\",\"url\":\"https://docs.upsonic.ai\",\"publisher\":{\"@id\":\"https://docs.upsonic.ai/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://docs.upsonic.ai/agentos/build/streaming#webpage\",\"url\":\"https://docs.upsonic.ai/agentos/build/streaming\",\"name\":\"Streaming answers\",\"description\":\"Answer a run with a stream that reaches your caller as it is written, and report the outcome.\",\"dateModified\":\"2026-10-27T12:17:32.038Z\",\"isPartOf\":{\"@id\":\"https://docs.upsonic.ai#website\"},\"breadcrumb\":{\"@id\":\"https://docs.upsonic.ai/agentos/build/streaming#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://docs.upsonic.ai/agentos/build/streaming#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"BUILD AGENTS\",\"item\":\"https://docs.upsonic.ai/agentos/build/agentos-yaml\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Streaming answers\",\"item\":\"https://docs.upsonic.ai/agentos/build/streaming\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://docs.upsonic.ai/agentos/build/streaming#article\",\"headline\":\"Streaming answers\",\"name\":\"Streaming answers\",\"description\":\"Answer a run with a stream that reaches your caller as it is written, and report the outcome.\",\"url\":\"https://docs.upsonic.ai/agentos/build/streaming\",\"mainEntityOfPage\":{\"@id\":\"https://docs.upsonic.ai/agentos/build/streaming#webpage\"},\"dateModified\":\"2026-10-27T12:17:32.038Z\",\"publisher\":{\"@id\":\"https://docs.upsonic.ai/#organization\"},\"isPartOf\":{\"@id\":\"https://docs.upsonic.ai#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"Upsonic AI\",\"creator\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","siteName":"Upsonic AI","nav":{"global":null,"tabs":[{"tab":"Upsonic Framework","pages":[{"title":"Upsonic Framework","href":"/get-started/introduction"}]},{"tab":"AgentOS","groups":[{"group":"GET STARTED","icon":"rocket","pages":[{"title":"What is AgentOS","sidebarTitle":"Introduction","href":"/agentos/get-started/introduction"},{"title":"Quickstart","href":"/agentos/get-started/quickstart"}]},{"group":"BUILD AGENTS","icon":"hammer","pages":[{"title":"agentos.yaml","href":"/agentos/build/agentos-yaml"},{"title":"Agent contract","href":"/agentos/build/agent-contract"},{"title":"Calling models","href":"/agentos/build/models"},{"title":"Human approvals","href":"/agentos/build/human-approvals"},{"title":"State and sessions","href":"/agentos/build/state-and-sessions"},{"title":"Memory","href":"/agentos/build/memory"},{"title":"Files and events","href":"/agentos/build/files-and-events"},{"title":"Child runs","href":"/agentos/build/child-runs"},{"title":"Secrets","description":"Give an agent API keys and passwords without putting them in its bundle.","href":"/agentos/build/secrets"},{"title":"Streaming answers","href":"/agentos/build/streaming"},{"title":"Network access","description":"Which hosts your agent can reach outside the platform, and how to ask for more.","href":"/agentos/build/network-access"}]},{"group":"SDKS \u0026 TOOLS","icon":"code","pages":[{"title":"Python and TypeScript SDKs","sidebarTitle":"SDKs","href":"/agentos/build/sdks"},{"title":"Agent frameworks","sidebarTitle":"Framework adapters","href":"/agentos/build/frameworks"},{"title":"Conformance kit","href":"/agentos/build/conformance"},{"title":"Example agents","sidebarTitle":"Examples","href":"/agentos/build/examples"}]},{"group":"FRAMEWORK EXAMPLES","icon":"puzzle-piece","pages":[{"title":"Framework examples","sidebarTitle":"Overview","href":"/agentos/frameworks/overview"},{"title":"CrewAI","href":"/agentos/frameworks/crewai"},{"title":"MCP servers as tools","sidebarTitle":"MCP","href":"/agentos/frameworks/mcp"},{"title":"Open WebUI","href":"/agentos/frameworks/open-webui"},{"title":"Upsonic","href":"/agentos/frameworks/upsonic"},{"title":"LangGraph","href":"/agentos/frameworks/langgraph"},{"title":"OpenAI Agents SDK","href":"/agentos/frameworks/openai-agents"},{"title":"Agno","href":"/agentos/frameworks/agno"},{"title":"Pydantic AI","href":"/agentos/frameworks/pydantic-ai"},{"title":"LangChain","href":"/agentos/frameworks/langchain"},{"title":"LlamaIndex","href":"/agentos/frameworks/llamaindex"},{"title":"Google ADK","href":"/agentos/frameworks/google-adk"},{"title":"Vercel AI SDK","href":"/agentos/frameworks/vercel-ai-sdk"},{"title":"Mastra","href":"/agentos/frameworks/mastra"},{"title":"OpenAI Agents SDK (JavaScript)","sidebarTitle":"OpenAI Agents SDK (JS)","href":"/agentos/frameworks/openai-agents-js"}]},{"group":"PLATFORM","icon":"layer-group","pages":[{"title":"Deploying agents","sidebarTitle":"Deploying","href":"/agentos/platform/deploying"},{"title":"Models and providers","href":"/agentos/platform/models-and-providers"},{"title":"Review queue","href":"/agentos/platform/review-queue"},{"title":"Guardrails","href":"/agentos/platform/guardrails"},{"title":"Network guardrails","href":"/agentos/platform/network-guardrails"},{"title":"Evals","href":"/agentos/platform/evals"},{"title":"Prompts","href":"/agentos/platform/prompts"},{"title":"Memory in the panel","sidebarTitle":"Memory","href":"/agentos/platform/memory"},{"title":"Webhooks","href":"/agentos/platform/webhooks"},{"title":"Audit log","href":"/agentos/platform/audit-log"},{"title":"Metrics","href":"/agentos/platform/metrics"},{"title":"Users and API keys","href":"/agentos/platform/users-and-api-keys"}]},{"group":"API REFERENCE","icon":"terminal","pages":[{"title":"API overview","sidebarTitle":"Overview","href":"/agentos/api/overview"},{"title":"Deploys API","sidebarTitle":"Deploys","href":"/agentos/api/deploys"},{"title":"Runs API","sidebarTitle":"Runs","href":"/agentos/api/runs"},{"title":"Holds API","sidebarTitle":"Holds","href":"/agentos/api/holds"},{"title":"Sessions API","sidebarTitle":"Sessions","href":"/agentos/api/sessions"},{"title":"Memory API","sidebarTitle":"Memory","href":"/agentos/api/memory"},{"title":"Files API","sidebarTitle":"Files","href":"/agentos/api/files"},{"title":"Evals API","sidebarTitle":"Evals","href":"/agentos/api/evals"},{"title":"Audit API","sidebarTitle":"Audit","href":"/agentos/api/audit"}]}]},{"tab":"Universal Commerce Protocol (UCP)","pages":[{"title":"Universal Commerce Protocol (UCP)","href":"/ucp"}]},{"tab":"Guides","pages":[{"title":"Guides","href":"/guides/1-create-a-task"}]},{"tab":"Reference","pages":[{"title":"Reference","href":"/reference/agent/agent"}]},{"tab":"Examples","pages":[{"title":"Examples","href":"/examples/overview/introduction"}]},{"tab":"Integrations","pages":[{"title":"Integrations","href":"/integrations/overview"}]},{"tab":"Community","pages":[{"title":"Community","href":"/community"}]},{"tab":"Changelog","pages":[{"title":"Changelog","href":"/changelog"}]}]},"title":"Streaming answers - Upsonic AI","buildId":"dpl_DFJrtvUi8HS5F9nkooKuDJsuD5BM","deploymentId":"dpl_DFJrtvUi8HS5F9nkooKuDJsuD5BM","dynamics":[],"chunks":[]}