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, 
   serviceOptions?: Readonly<AxAIServiceOptions>): AxAIService;

Defined in: https://github.com/ax-llm/ax/blob/e690b4823b8309e258594064abe941d4cff6ef89/src/ax/ai/capabilities.ts#L502

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
serviceOptions?Readonly<AxAIServiceOptions>-

Returns

AxAIService

The optimal AI service provider

Throws

Error if no suitable provider found or requirements not met

Docs