Streaming Responses

Streaming responses are supported in both calling external APIs, and setting up your Xano APIs to deliver streaming responses.

Calling an External Streaming API

You can use the Streaming External API Request endpoint to call an API that returns a stream in almost exactly the same way as you call normal APIs from your function stacks. The only difference is the structure of data returned, which would typically be an array of items that you would leverage a For Each loop to work with.

Streaming Xano API Responses

When delivering certain types of API responses, you may want to 'stream' this response (similar to your favorite AI-powered chatbots). In Xano, this is possible with a simple combination of a For Each loop and a Streaming API Response function.

We'll be using a poem in the public domain to demonstrate the streaming response. You can copy the sample below and use it in your own function stacks to test.

["Two roads diverged in a yellow wood,","And sorry I could not travel both","And be one traveler, long I stood","And looked down one as far as I could","To where it bent in the undergrowth;","","Then took the other, as just as fair,","And having perhaps the better claim,","Because it was grassy and wanted wear;","Though as for that the passing there","Had worn them really about the same,","","And both that morning equally lay","In leaves no step had trodden black.","Oh, I kept the first for another day!","Yet knowing how way leads on to way,","I doubted if I should ever come back.","","I shall be telling this with a sigh","Somewhere ages and ages hence:","Two roads diverged in a wood, and I—","I took the one less traveled by,","And that has made all the difference."]

Data that you use for a streaming response needs to be separated into logical pieces. In this example, each item in the array is a new line in the poem. It would typically make the most sense to build a streaming response against an array just for ease of implementation.

Setting up a streaming response

  • You can now test your streaming API, and should see each item in the array streamed as part of the response.

Please note that your front-end must support streaming responses. If it does not, the response can still be delivered traditionally.

Using Run & Debug will not display a stream, and only the entire response once the stream has completed.

Testing your Streaming Response

Testing in Postman

  • Create a new request with type HTTP

  • Paste your API endpoint URL in the URL input, and click Send.

  • You will see your API response delivered in the result panel.

Testing in Insomnia

  • Create a new request with type Event Stream

  • Paste your API endpoint URL in the URL input, and click Connect

  • You will see your API response delivered in the result panel.

Last updated