Skip to main content

scx_forge_agent/
http.rs

1// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2// SPDX-License-Identifier: GPL-2.0-only
3//! HTTP client for an OpenAI-compatible inference endpoint: large request bodies
4//! and long server think times.
5
6use anyhow::{Context, Result};
7use std::time::Duration;
8
9/// Build a client suitable for multi-KB JSON prompts and slow inference APIs.
10///
11/// - Long connect (5 min) and overall (1 h) timeouts for slow inference.
12/// - HTTP/1.1 only: avoids sporadic HTTP/2 stalls seen with some cloud gateways.
13/// - TCP keepalive so idle long responses are less likely to be dropped.
14pub fn build_http_client() -> Result<reqwest::Client> {
15    reqwest::Client::builder()
16        .connect_timeout(Duration::from_secs(300))
17        .timeout(Duration::from_secs(3_600))
18        .tcp_keepalive(Duration::from_secs(60))
19        .pool_idle_timeout(Duration::from_secs(45))
20        .pool_max_idle_per_host(4)
21        .user_agent(concat!("scx-forge-agent/", env!("CARGO_PKG_VERSION")))
22        .http1_only()
23        .build()
24        .context("build reqwest HTTP client")
25}