Documentation

Build LLM-powered agents
with production-ready TypeScript

DSPy for TypeScript. Working with LLMs is complex—they don't always do what you want. DSPy makes it easier to build amazing things with LLMs. Just define your inputs and outputs (signature) and an efficient prompt is auto-generated and used. Connect together various signatures to build complex systems and workflows using LLMs.

15+ LLM Providers
End-to-end Streaming
Auto Prompt Tuning

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

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