Module batch

Module batch 

Source
Expand description

AI-04 (#194): Batch API support and half-price metering.

OpenAI and Anthropic batch APIs are 50% cheaper than real-time endpoints. The gateway proxies batch creation/status/cancel as a passthrough (no translation), and when batch results are retrieved the JSONL output file is parsed line-by-line. Each line’s usage object is metered at the batch rate (batch_input_per_1k_micros / batch_output_per_1k_micros, falling back to standard rates when batch-specific rates are not configured).

The half-price cost computation already exists in ai::cost::PricingTable::cost_micros(batch=true); this module provides the JSONL parsing and batch result metering.

Structs§

BatchMeteringSummary
Summary of a batch result file’s metering.
BatchPromptTokenDetails
The prompt_tokens_details sub-object.
BatchResponse
The response field of a batch result line.
BatchResultLine
One line of a batch result JSONL file. The OpenAI Batch API result format has this shape per line:
BatchUsage
The usage field of a batch response.

Functions§

meter_batch_results
Parse a batch result JSONL file and compute the total cost at the batch (50% discount) rate. Each line is parsed independently; a malformed line is counted as an error and skipped.