Example: Streaming API Call

The Agents API streams responses by default using Server-Sent Events (SSE). This allows you to receive real-time updates as the agent thinks and acts.

Request

curl -X POST \
  -H "Content-Type: application/json" \
  -H "Accept: text/event-stream" \
  -H "Authorization: Bearer sk-ptr-..." \
  -d '{"message": "Can you introduce yourself?"}' \
  "https://pointerapi.com"

Streaming Response (abridged)

data: {"type":"agent_started","session":"8lh87hwhju0xoxy"}
data: {"type":"agent_thinking_start","session":"8lh87hwhju0xoxy"}
data: {"type":"agent_thinking","session":"8lh87hwhju0xoxy","content":"The user is asking me to introduce myself."}
data: {"type":"agent_response_start","session":"8lh87hwhju0xoxy"}
data: {"type":"agent_response","session":"8lh87hwhju0xoxy","content":"Hello! I'm Pointer, a general-purpose AI agent designed to help you…"}
data: {"type":"agent_cost","session":"8lh87hwhju0xoxy","cost":"0.0934"}
data: {"type":"agent_completed","session":"8lh87hwhju0xoxy"}
For an explanation of every type value, see Streaming Message Types.

Session Handling

  • Auto-Creation: If you do not specify a session ID, a new one is automatically created.
  • Continue a Session: Append ?session=[SESSION_ID] to the URL.