Skip to main content
BaseProvider is the core extension point for implementing custom model providers in ai-query.

Import

Constructor

Parameters

str
Optional provider API key.
HTTPTransport
Optional custom HTTP transport.
Any
Additional provider-specific configuration stored on self.config.

Required Attributes

name

Provider identifier used for provider_options lookup. Example:

Required Methods

generate()

Generate a complete response.

stream()

Stream a response incrementally. The final yielded chunk should set is_final=True and include usage and finish metadata when available.

Optional Methods

embed()

Override this if the provider supports embeddings.

embed_many()

Batch embedding method. The base class default implementation runs embed() in parallel.

Properties

transport

Returns the transport passed to the constructor or auto-detects the default transport for the current runtime.

Helper Methods

get_provider_options()

Extracts the options for the current provider using self.name.

_fetch_resource_as_base64()

Fetch a remote resource and convert it to base64 plus media type. Useful for multimodal providers.

_parse_sse_line()

Extract the data: payload from an SSE line.

_parse_sse_json()

Parse an SSE data: line as JSON.

_accumulate_usage()

Accumulate usage counters in-place.

Minimal Example