HTTP Fetch Timeouts

Oracle Programs in SEDA can make HTTP calls to external APIs, but these calls are subject to timeout constraints to ensure predictable execution times. Similar to gas limits for computational work, HTTP timeouts control how long your program can spend on external API calls.

The SDK implements two timeout mechanisms:

  1. Per-request timeout: Configurable timeout for individual HTTP requests

  2. Global timeout: Total time limit for all HTTP requests in a single execution

Timeout Configuration

Default Values

  • Per-request timeout: 2 seconds (2,000ms)

  • Global timeout: 20 seconds (20,000ms)

Per-Request Timeout

Each HTTP request has a default timeout of 2 seconds. For APIs that require more time to respond, you can configure a custom timeout using HttpFetchOptions:

use seda_sdk_rs::{http::http_fetch, HttpFetchOptions};

let response = http_fetch(
    "https://httpbin.org/get",
    Some(HttpFetchOptions {
        timeout_ms: Some(3_000), // 3 seconds timeout
        ..Default::default()
    })
);

When to Use Custom Timeouts

Consider increasing the timeout when working with APIs that typically require more time to respond:

  • AI/ML services (OpenAI, Anthropic, etc.) that often take 3-5 seconds

  • Data processing APIs that perform heavy computations

  • Reliable but slow APIs that consistently require more time

Global Timeout Behavior

Oracle Programs have a total time budget of 20 seconds for all HTTP requests combined. This global timeout works as follows:

  1. Each HTTP request consumes time from the 20-second budget

  2. The global timeout doesn't reset between requests

  3. Once the global timeout is exceeded, all subsequent HTTP requests fail

Example: Multiple HTTP Requests

use seda_sdk_rs::{http::http_fetch, HttpFetchOptions};

// First request: 3 seconds
let response1 = http_fetch(
    "https://slow-api.com/data1",
    Some(HttpFetchOptions {
        timeout_ms: Some(3_000),
        ..Default::default()
    })
);

// Second request: 5 seconds (total: 8 seconds)
let response2 = http_fetch(
    "https://slow-api.com/data2",
    Some(HttpFetchOptions {
        timeout_ms: Some(5_000),
        ..Default::default()
    })
);

// Third request: 15 seconds (total: 23 seconds) - This will fail!
let response3 = http_fetch(
    "https://slow-api.com/data3",
    Some(HttpFetchOptions {
        timeout_ms: Some(15_000),
        ..Default::default()
    })
);

Last updated

Was this helpful?