providerbatch

package
v1.5.4 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2026 License: MIT Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package providerbatch owns request partitioning for provider APIs that bound a request by an input count and by an aggregate token budget.

Text is counted in UTF-8 bytes, which is a conservative upper bound on the number of text tokens: a provider tokenizer never yields more tokens than the input has bytes. A zero limit means the provider documents no such bound, so that limit never splits a request.

The package also owns the one record of provider-reported token usage for a completed request, which the embedding and rerank providers share.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ForBatches

func ForBatches(ctx context.Context, operation string, count, maxInputs, maxTokens int, tokens func(int) int, send func(int, int) error) error

ForBatches splits count inputs into consecutive requests and sends each one exactly once, in order.

maxInputs bounds the inputs in one request and maxTokens bounds the request's aggregate cost as reported by tokens; both values are the provider's own documented ceilings. An input that is larger than maxTokens on its own is still sent alone: the provider's own refusal stays visible instead of being hidden or pre-empted here, and no input text is shortened.

A failing send stops the sequence and its error is returned with the failed input range, so a caller that must fail as a whole cannot mistake earlier successes for a result.

func RecordUsage

func RecordUsage(ctx context.Context, operation, provider, model string, inputs, totalTokens int)

RecordUsage reports the token accounting a provider returned for one request it completed: one record per completed request, so billable work is neither lost nor multiplied by the inputs a request carried and never replaced by a locally computed estimate.

operation names what the request did ("embedding", "rerank"); inputs is the number of inputs that request carried. A caller records usage as soon as the provider response exists, before deciding whether its payload is usable, so a response later rejected as unusable still reports the tokens it cost.

Types

This section is empty.

Jump to

Keyboard shortcuts

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