axSelectOptimalProvider Generated TypeScript API reference. typescript api api/reference build/apidocs/Function.axSelectOptimalProvider.md function axSelectOptimalProvider

axSelectOptimalProvider

TypeScript
function axSelectOptimalProvider(
   request: AxChatRequest, 
   availableProviders: AxAIService<unknown, unknown, string>[], 
   options: object): AxAIService;

Defined in: https://github.com/ax-llm/ax/blob/5b28f9093bb70863b59459bb6df5062d005bce41/src/ax/ai/capabilities.ts#L465

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

TypeScript
// 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

ParameterTypeDescription
requestAxChatRequestThe chat request to find a provider for
availableProvidersAxAIService<unknown, unknown, string>[]Array of available AI service providers
options{ allowDegradation?: boolean; requireExactMatch?: boolean; }Selection options
options.allowDegradation?booleanAllow providers that require content processing fallbacks
options.requireExactMatch?booleanOnly return providers with full capability support

Returns

AxAIService

The optimal AI service provider

Throws

Error if no suitable provider found or requirements not met

Docs