Skip to content

BackendAdapter

Defined in: packages/ai.matey.types/src/adapters.ts:264

Backend adapter interface.

Backend adapters handle actual API calls to AI providers. They transform universal IR into provider-specific API requests and normalize responses back to IR.

TRequest = unknown

Provider-specific request type

TResponse = unknown

Provider-specific response type

readonly metadata: AdapterMetadata

Defined in: packages/ai.matey.types/src/adapters.ts:268

Adapter metadata for identification and capabilities.

optional estimateCost(request): Promise<number | null>

Defined in: packages/ai.matey.types/src/adapters.ts:342

Optional: Estimate cost for a request.

IRChatRequest

IR request to estimate cost for

Promise<number | null>

Estimated cost in USD (or null if unavailable)


execute(request, signal?): Promise<IRChatResponse>

Defined in: packages/ai.matey.types/src/adapters.ts:313

Execute non-streaming chat completion request.

IRChatRequest

Universal IR request

AbortSignal

Optional AbortSignal for cancellation

Promise<IRChatResponse>

Universal IR response

If API key is invalid

If request is invalid for this provider

If provider API returns error

If network request fails

If response parsing fails


executeStream(request, signal?): IRChatStream

Defined in: packages/ai.matey.types/src/adapters.ts:327

Execute streaming chat completion request.

IRChatRequest

Universal IR request

AbortSignal

Optional AbortSignal for cancellation

IRChatStream

Universal IR stream of chunks

If API key is invalid

If request is invalid for this provider

If provider API returns error

If network request fails

If stream parsing or processing fails


fromIR(request): TRequest

Defined in: packages/ai.matey.types/src/adapters.ts:283

Convert universal IR request to provider-specific format.

Useful for:

  • Debugging: Inspect what will be sent to the provider
  • Testing: Test conversion logic without making API calls
  • Transparency: See provider-specific request structure

IRChatRequest

Universal IR request

TRequest

Provider-specific request object

If request is invalid for this provider

If conversion fails


optional healthCheck(): Promise<boolean>

Defined in: packages/ai.matey.types/src/adapters.ts:334

Optional: Health check to verify backend is available.

Promise<boolean>

true if backend is healthy and available


optional listModels(options?): Promise<ListModelsResult>

Defined in: packages/ai.matey.types/src/adapters.ts:357

Optional: List available models from this backend.

Behavior depends on provider:

  • Providers with API endpoints (OpenAI, Groq): Fetch from API with caching
  • Providers without endpoints (Anthropic): Return static list from config or defaults
  • Can be overridden via config.models or config.modelsEndpoint

ListModelsOptions

Options for listing models (filtering, cache control)

Promise<ListModelsResult>

List of available models with metadata

If remote fetch fails

If network request fails


toIR(response, originalRequest, latencyMs): IRChatResponse

Defined in: packages/ai.matey.types/src/adapters.ts:299

Convert provider-specific response to universal IR.

Useful for:

  • Testing: Convert mock provider responses to IR
  • Debugging: Parse provider responses manually
  • Format conversion: Use backend as response converter

TResponse

Provider-specific response object

IRChatRequest

Original IR request (for context)

number

Request latency in milliseconds

IRChatResponse

Universal IR response

If conversion fails