Durablr API Examples

Real-world examples of using Durablr to handle Server-Sent Events streams without serverless timeouts

🚀 Getting Started

# Durablr API is hosted at:
https://www.durablr.run

The API is available at https://www.durablr.run

🤖 OpenAI Chat Streaming

Stream OpenAI chat completions through webhooks to avoid serverless timeouts:

curl -X POST https://www.durablr.run/stream/subscribe \ -H "Content-Type: application/json" \ -d '{ "method": "POST", "streamUrl": "https://api.openai.com/v1/chat/completions", "webhookUrl": "https://webhook.site/your-unique-url", "headers": { "Authorization": "Bearer YOUR_OPENAI_API_KEY", "Content-Type": "application/json" }, "body": { "model": "gpt-4", "messages": [{"role": "user", "content": "Write a creative story about space exploration"}], "stream": true, "max_tokens": 500 } }'

Response:

{"streamId": "7f8c9d2e-4b5a-1c3d-9e8f-2a1b3c4d5e6f"}

📡 Simple GET Stream

Subscribe to any Server-Sent Events endpoint:

curl -X POST https://www.durablr.run/stream/subscribe \ -H "Content-Type: application/json" \ -d '{ "streamUrl": "https://your-sse-endpoint.com/events", "webhookUrl": "https://webhook.site/your-unique-url", "headers": { "Authorization": "Bearer YOUR_TOKEN" } }'

🔗 Testing with Webhook.site

  1. 1.Go to webhook.site and copy your unique URL
  2. 2.Replace your-unique-url in the examples above
  3. 3.Run the curl command
  4. 4.Watch real-time events arrive at your webhook URL

📨 Webhook Response Format

Durablr forwards streaming chunks in real-time:

Stream Chunk (OpenAI example):

{ "streamId": "7f8c9d2e-4b5a-1c3d-9e8f-2a1b3c4d5e6f", "type": "chunk", "data": "data: {\"id\":\"chatcmpl-ABC123\",\"object\":\"chat.completion.chunk\",\"created\":1756648138,\"model\":\"gpt-4-0613\",\"choices\":[{\"index\":0,\"delta\":{\"content\":\" couldn\"},\"logprobs\":null,\"finish_reason\":null}]}\n\n", "timestamp": "2025-08-31T13:49:05.649Z" }

Stream Completion:

{ "streamId": "7f8c9d2e-4b5a-1c3d-9e8f-2a1b3c4d5e6f", "type": "completed", "timestamp": "2025-08-31T13:49:15.123Z" }

Notes:

  • • Each webhook call may contain multiple SSE chunks batched together
  • • Data is forwarded exactly as received from the source API
  • • Parse the data: lines to extract the actual JSON responses

⚙️ Management API

Get Active Streams:

curl https://www.durablr.run/stream/active
{"activeStreams": ["7f8c9d2e-4b5a-1c3d-9e8f-2a1b3c4d5e6f"], "count": 1}

Stop a Stream:

curl -X DELETE https://www.durablr.run/stream/subscribe/7f8c9d2e-4b5a-1c3d-9e8f-2a1b3c4d5e6f
{"message": "Stream stopped", "streamId": "7f8c9d2e-4b5a-1c3d-9e8f-2a1b3c4d5e6f"}

🌟 Use Cases

🤖

OpenAI Streaming

Handle long AI responses without timeouts

📊

Analytics Streams

Real-time analytics and metrics feeds

🔄

Data Processing

Long-running data transformation jobs

📈

Stock Feeds

Real-time financial data streams

📡

IoT Events

Device telemetry and sensor data

💬

Chat APIs

Streaming chat and messaging systems