Skip to main content
The Advanced Agent API can stream responses. This allows you to process data incrementally as it becomes available, rather than waiting for the full payload. The following example shows how to manage a stream call of the Advanced Agent API with cURL:
curl -N \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Accept: text/event-stream" \
  -H "Content-Type: application/json" \
  -X POST https://api.you.com/v1/agents/runs \
  -d '{
    "agent": "advanced",
    "input": "You are a biologist studying the impacts of microplastics. Explain what microplastics are to a group of engineers, explain the impacts of microplastics on the body, and what the common source and dosage of microplastics are. High-light what a safe dosage might be and how to achieve it",
    "stream": true
  }'
Below is the summary excerpt of the streaming events for the input:
id: 0
event: response.created
data: {"seq_id": 0, "type": "response.created"}

id: 1
event: response.starting
data: {"seq_id": 1, "type": "response.starting"}

id: 2
event: response.output_item.added
data: {"seq_id": 2, "type": "response.output_item.added", "response": {"output_index": 0}}

id: 3
event: response.output_text.delta
data: {"seq_id": 3, "type": "response.output_text.delta", "response": {"output_index": 0, "type": "message.answer", "delta": "## \ud83e\uddec Microplastics: What Engineers Need to Know\n\n---\n\n> **Key Takeaway:**  \n> Microplastic"}}

id: 4
event: response.output_text.delta
data: {"seq_id": 4, "type": "response.output_text.delta", "response": {"output_index": 0, "type": "message.answer", "delta": "s are tiny plastic particles that are pervasive in the environment and can enter the human body through various"}}

id: 5
event: response.output_text.delta
data: {"seq_id": 5, "type": "response.output_text.delta", "response": {"output_index": 0, "type": "message.answer", "delta": " routes. While the full health impacts are still being studied, minimizing exposure is recommended due"}}

// Content omitted for brevity

id: 58
event: response.output_text.delta
data: {"seq_id": 58, "type": "response.output_text.delta", "response": {"output_index": 0, "type": "message.answer", "delta": " safe exposure level, engineers and the public can take practical steps to reduce intake and support systemic"}}

id: 59
event: response.output_text.delta
data: {"seq_id": 59, "type": "response.output_text.delta", "response": {"output_index": 0, "type": "message.answer", "delta": " solutions. Ongoing research and innovation\u2014especially in materials science, filtration, and waste management\u2014will be cru"}}

id: 60
event: response.output_text.delta
data: {"seq_id": 60, "type": "response.output_text.delta", "response": {"output_index": 0, "type": "message.answer", "delta": "cial in addressing this emerging challenge.\n\n---\n\n> **Engineers play a vital role in developing solutions to r"}}

id: 61
event: response.output_text.delta
data: {"seq_id": 61, "type": "response.output_text.delta", "response": {"output_index": 0, "type": "message.answer", "delta": " protect public health.**"}}

id: 62
event: response.output_item.done
data: {"seq_id": 62, "type": "response.output_item.done", "response": {"output_index": 0}}

id: 63
event: response.done
data: {"seq_id": 63, "type": "response.done", "response": {"run_time_ms": "29.862", "finished": true}}