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.
Extended by
Section titled “Extended by”Type Parameters
Section titled “Type Parameters”TRequest
Section titled “TRequest”TRequest = unknown
Provider-specific request type
TResponse
Section titled “TResponse”TResponse = unknown
Provider-specific response type
Properties
Section titled “Properties”metadata
Section titled “metadata”
readonlymetadata:AdapterMetadata
Defined in: packages/ai.matey.types/src/adapters.ts:268
Adapter metadata for identification and capabilities.
Methods
Section titled “Methods”estimateCost()?
Section titled “estimateCost()?”
optionalestimateCost(request):Promise<number|null>
Defined in: packages/ai.matey.types/src/adapters.ts:342
Optional: Estimate cost for a request.
Parameters
Section titled “Parameters”request
Section titled “request”IR request to estimate cost for
Returns
Section titled “Returns”Promise<number | null>
Estimated cost in USD (or null if unavailable)
execute()
Section titled “execute()”execute(
request,signal?):Promise<IRChatResponse>
Defined in: packages/ai.matey.types/src/adapters.ts:313
Execute non-streaming chat completion request.
Parameters
Section titled “Parameters”request
Section titled “request”Universal IR request
signal?
Section titled “signal?”AbortSignal
Optional AbortSignal for cancellation
Returns
Section titled “Returns”Promise<IRChatResponse>
Universal IR response
Throws
Section titled “Throws”If API key is invalid
Throws
Section titled “Throws”If request is invalid for this provider
Throws
Section titled “Throws”If provider API returns error
Throws
Section titled “Throws”If network request fails
Throws
Section titled “Throws”If response parsing fails
executeStream()
Section titled “executeStream()”executeStream(
request,signal?):IRChatStream
Defined in: packages/ai.matey.types/src/adapters.ts:327
Execute streaming chat completion request.
Parameters
Section titled “Parameters”request
Section titled “request”Universal IR request
signal?
Section titled “signal?”AbortSignal
Optional AbortSignal for cancellation
Returns
Section titled “Returns”Universal IR stream of chunks
Throws
Section titled “Throws”If API key is invalid
Throws
Section titled “Throws”If request is invalid for this provider
Throws
Section titled “Throws”If provider API returns error
Throws
Section titled “Throws”If network request fails
Throws
Section titled “Throws”If stream parsing or processing fails
fromIR()
Section titled “fromIR()”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
Parameters
Section titled “Parameters”request
Section titled “request”Universal IR request
Returns
Section titled “Returns”TRequest
Provider-specific request object
Throws
Section titled “Throws”If request is invalid for this provider
Throws
Section titled “Throws”If conversion fails
healthCheck()?
Section titled “healthCheck()?”
optionalhealthCheck():Promise<boolean>
Defined in: packages/ai.matey.types/src/adapters.ts:334
Optional: Health check to verify backend is available.
Returns
Section titled “Returns”Promise<boolean>
true if backend is healthy and available
listModels()?
Section titled “listModels()?”
optionallistModels(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
Parameters
Section titled “Parameters”options?
Section titled “options?”Options for listing models (filtering, cache control)
Returns
Section titled “Returns”Promise<ListModelsResult>
List of available models with metadata
Throws
Section titled “Throws”If remote fetch fails
Throws
Section titled “Throws”If network request fails
toIR()
Section titled “toIR()”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
Parameters
Section titled “Parameters”response
Section titled “response”TResponse
Provider-specific response object
originalRequest
Section titled “originalRequest”Original IR request (for context)
latencyMs
Section titled “latencyMs”number
Request latency in milliseconds
Returns
Section titled “Returns”Universal IR response
Throws
Section titled “Throws”If conversion fails