batchhttp

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 13 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 batchhttp is the shared plumbing under every provider's BatchTranscriber: credential extraction, bounded HTTP exchanges, the closed status-to-ProviderError mapping, streaming multipart bodies, the poll loop for job-style APIs, and word-to-segment grouping. It holds no provider knowledge; each adapter owns its own request and response shapes.

Index

Constants

View Source
const (
	CodeAuthenticationFailed = "authentication_failed"
	CodeRateLimited          = "provider_rate_limited"
	CodeUnavailable          = "provider_unavailable"
	CodeInvalidRequest       = "invalid_request"
	CodeInputTooLarge        = "input_too_large"
	CodeUnsupportedMedia     = "unsupported_media"
	CodeRequestTimeout       = "request_timeout"
	CodeProviderError        = "provider_error"
)

Provider-error codes on the closed set the relay's classifier understands. Any other string collapses to provider_error downstream, so adapters use only these.

View Source
const DefaultMaxResponseBytes int64 = 64 << 20

DefaultMaxResponseBytes bounds a transcript body. Word-level output for several hours of audio runs to tens of megabytes; 64 MiB leaves room while still refusing an unbounded stream.

Variables

This section is empty.

Functions

func Client

func Client(client *http.Client) *http.Client

Client defaults a nil client.

func Credential

func Credential(plan protocol.SessionPlan) (string, error)

Credential returns the plan's provider key. Bearer is the norm; relay_access is accepted because a relay connector that synthesizes the plan itself labels the same permanent key either way (see the realtime adapters' acceptableCredentialKind).

func DecodeJSON

func DecodeJSON(body []byte, target any) error

DecodeJSON unmarshals a body, mapping decode errors onto Malformed.

func Failed

func Failed(extension, detail string) *runtimepkg.ProviderError

Failed is the error for a job the provider itself reports as failed. It is not retryable by default: the same audio fails the same way.

func GroupWords

func GroupWords(words []Word, gapMS int64) []runtimepkg.BatchSegment

GroupWords folds word timings into segments for providers that return no coarser unit. A new segment starts on a speaker change or a silence longer than gapMS. Words are joined with single spaces; providers that carry their own spacing tokens should strip them before calling.

func JoinSegments

func JoinSegments(segments []runtimepkg.BatchSegment) string

JoinSegments renders the full transcript from segments when the provider returns no whole-text field.

func Malformed

func Malformed(cause error) *runtimepkg.ProviderError

Malformed is the error for a 2xx body the adapter could not interpret.

func Multipart

func Multipart(fields []MultipartField, fileField, fileName, fileContentType string, audio io.Reader) (io.ReadCloser, string)

Multipart streams a multipart/form-data body: the fields first, then one file part read from audio as the HTTP client consumes the request, so a multi-gigabyte upload is never held in memory. The returned reader must be drained or closed by the HTTP client; the content type carries the boundary.

func Poll

func Poll(ctx context.Context, interval time.Duration, check func(context.Context) (bool, error)) error

Poll calls check at the interval until it reports done, fails, or the context ends. A context deadline becomes request_timeout so a job the provider never finishes is classified like any other stall.

func RawExtension

func RawExtension(key string, body []byte) map[string]json.RawMessage

RawExtension wraps a body for BatchTranscription.Extensions when it is valid JSON; invalid bodies are dropped rather than quoted.

func Rewind

func Rewind(audio io.Seeker) error

Rewind seeks the audio back to its start for a second pass.

func SecondsToMS

func SecondsToMS(seconds float64) int64

SecondsToMS converts a floating-point seconds value as vendors report it.

func StatusError

func StatusError(extension string, status int, body []byte) *runtimepkg.ProviderError

StatusError maps a non-2xx status onto the closed code set. The body is retained under the extension key for local diagnostics only; the message never quotes it, because a vendor error string is not caller-safe.

func TransportError

func TransportError(ctx context.Context, err error) error

TransportError classifies a failure to complete an HTTP exchange.

Types

type MultipartField

type MultipartField struct{ Name, Value string }

MultipartField is one non-file part.

type Response

type Response struct {
	Status int
	Header http.Header
	Body   []byte
}

Response is one bounded HTTP exchange.

func Do

func Do(client *http.Client, request *http.Request, maxBody int64) (*Response, error)

Do performs the request and reads at most maxBody bytes of the response. A body that exceeds the bound is a provider_error rather than a truncated document parsed as if complete. Transport failures are classified: a context deadline is request_timeout, anything else provider_unavailable, both retryable.

Redirects are never followed. The endpoint policy validated the URL the adapter dialed, and the credential is already on the request; Go's client keeps custom headers (X-API-Key, xi-api-key) on a cross-host redirect, so following one would hand the provider key to whatever host the response named. A 3xx comes back as itself and is classified provider_error.

type Word

type Word struct {
	Text    string
	StartMS int64
	EndMS   int64
	Speaker string
}

Word is a provider word with timing, the unit most batch APIs return.

Jump to

Keyboard shortcuts

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