axSelectOptimalProvider
function axSelectOptimalProvider(
request: AxChatRequest,
availableProviders: AxAIService<unknown, unknown, string>[],
options: object): AxAIService;
Defined in: https://github.com/ax-llm/ax/blob/d2df625e2c2fd70a090d6321c042579c2819f0d1/src/ax/ai/capabilities.ts#L450
Automatically selects the optimal AI provider for a given request.
Analyzes the request requirements, scores available providers, and returns the best match based on capability compatibility and scoring algorithm.
Example
// Automatic selection with degradation allowed
const provider = axSelectOptimalProvider(
multiModalRequest,
[openai, gemini, cohere],
{ allowDegradation: true }
);
// Strict matching - must support all features natively
const provider = axSelectOptimalProvider(
imageRequest,
[openai, gemini],
{ requireExactMatch: true }
);
Parameters
| Parameter | Type | Description |
|---|---|---|
request | AxChatRequest | The chat request to find a provider for |
availableProviders | AxAIService<unknown, unknown, string>[] | Array of available AI service providers |
options | { allowDegradation?: boolean; requireExactMatch?: boolean; } | Selection options |
options.allowDegradation? | boolean | Allow providers that require content processing fallbacks |
options.requireExactMatch? | boolean | Only return providers with full capability support |
Returns
The optimal AI service provider
Throws
Error if no suitable provider found or requirements not met