> For the complete documentation index, see [llms.txt](https://docs.seda.xyz/home/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.seda.xyz/home/for-developers/define-your-data-source/accessing-a-public-api/http-fetch-timeouts.md).

# 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`:

```rust
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

```rust
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()
    })
);
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.seda.xyz/home/for-developers/define-your-data-source/accessing-a-public-api/http-fetch-timeouts.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
