axSelectOptimalProvider
function axSelectOptimalProvider(
request: AxChatRequest,
availableProviders: AxAIService<unknown, unknown, string>[],
options: object): AxAIService;
Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/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