pig/ai/http
Values
pub fn build_request(
url: String,
headers: List(#(String, String)),
body: String,
) -> Result(request.Request(String), error.AiError)
Build a POST request from URL, headers, and body. Pure — no network IO. Returns Error if URL is malformed.
pub const default_timeout_ms: Int
Default HTTP timeout for LLM API calls (120 seconds).
pub fn map_http_error(err: httpc.HttpError) -> error.AiError
Map a gleam_httpc transport error to AiError. Pure — no network IO.
pub fn map_response(
resp: response.Response(String),
) -> Result(String, error.AiError)
Map an HTTP response to a Result(String, AiError). 2xx -> Ok(body), 429 -> RateLimited, other -> ApiError. Pure — no network IO.
pub fn post(
url: String,
headers: List(#(String, String)),
body: String,
) -> Result(String, error.AiError)
Send a POST request with the default 120-second timeout. Returns response body or AiError.
pub fn post_with_timeout(
url: String,
headers: List(#(String, String)),
body: String,
timeout_ms: Int,
) -> Result(String, error.AiError)
Send a POST request with an explicit timeout in milliseconds. Returns response body or AiError.