Functions

request

fn (method: Str, url: Str): ::hot::http/HttpResponse
fn (method: Str, url: Str, additional-headers: Map): ::hot::http/HttpResponse
fn (method: Str, url: Str, additional-headers: Map, body: Any): ::hot::http/HttpResponse
fn (method: Str, url: Str, additional-headers: Map, body: Any, api-key: Str): ::hot::http/HttpResponse

Make an authenticated HTTP request to the xAI API.

Automatically includes the Authorization header using the xai.api.key from context. Additional headers can be provided to merge/override defaults. When a body is provided, Content-Type is set to application/json and the body is serialized.

Supports 2 to 5 arguments: (method, url), (method, url, headers), (method, url, headers, body), or (method, url, headers, body, api-key).

Example

// Simple GET request
response request("GET", "https://api.x.ai/v1/models")

// POST with body
response request("POST", "https://api.x.ai/v1/responses", {}, {
    model: "grok-3-mini",
    input: "Hello"
})
Context Vars: xai.api.key

request-stream

fn (method: Str, url: Str, additional-headers: Map, body: Any): ::hot::http/StreamingHttpResponse
fn (method: Str, url: Str, additional-headers: Map, body: Any, format: Str): ::hot::http/StreamingHttpResponse
fn (method: Str, url: Str, additional-headers: Map, body: Any, format: Str, api-key: Str): ::hot::http/StreamingHttpResponse

Make an authenticated streaming HTTP request to the xAI API.

Returns a StreamingHttpResponse with an iterator body for processing SSE events. Automatically includes the Authorization header using the xai.api.key from context.

Supports 4 to 6 arguments: (method, url, headers, body), (method, url, headers, body, format), or (method, url, headers, body, format, api-key).

Example

response request-stream("POST", "https://api.x.ai/v1/responses", {}, {
    model: "grok-3-mini",
    input: "Hello",
    stream: true
})

events collect(response.body)
// events is a Vec of SSE event objects
Context Vars: xai.api.key

Types

HttpError

HttpError type {
    status: Int,
    headers: Map,
    body: Any
}