httpx

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package httpx provides HTTP utilities for model providers. It includes retry logic with exponential backoff, Retry-After support, and context cancellation handling.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is an HTTP client with built-in retry logic and backoff. It rebuilds request bodies to support retries on idempotent failures.

func NewClient

func NewClient(base *http.Client) *Client

NewClient creates a new HTTP client with optional base client. If base is nil, http.DefaultClient is used.

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *http.Request) (*http.Response, error)

Do executes an HTTP request with automatic retry on 429 and 5xx errors. It uses exponential backoff with jitter and honors the Retry-After header. The request body must be rebuildable via req.GetBody or provided as bytes. Returns the response or an error wrapping context.Canceled if the context is canceled.

type SSEEvent

type SSEEvent struct {
	// Event is the event type (optional).
	Event string
	// Data is the event data payload (may be empty).
	Data string
	// ID is the event ID (optional).
	ID string
}

SSEEvent represents a single Server-Sent Event.

type SSEReader

type SSEReader struct {
	// contains filtered or unexported fields
}

SSEReader reads Server-Sent Events from an io.Reader. It skips comments (lines starting with :) and handles multi-line data.

func NewSSEReader

func NewSSEReader(r io.Reader) *SSEReader

NewSSEReader creates a new SSE reader from an io.Reader.

func (*SSEReader) Next

func (s *SSEReader) Next() (SSEEvent, error)

Next reads the next SSE event from the stream. Returns io.EOF when the stream is complete. Skips comments and empty events.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL