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

AxMultiServiceRouter

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/ai/multiservice.ts#L43

Type Parameters

Type ParameterDefault type
TServices extends readonly ( | AxAIService | AxAIServiceListItem<any, any, any>)[]readonly AxAIService[]
TModelKeyExtractAllModelKeys<TServices>

Implements

Constructors

Constructor

new AxMultiServiceRouter<TServices, TModelKey>(services: TServices): AxMultiServiceRouter<TServices, TModelKey>;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/ai/multiservice.ts#L69

Constructs a new multi-service router. It validates that each service provides a unique set of model keys, then builds a lookup (map) for routing the chat/embed requests.

Parameters

ParameterType
servicesTServices

Returns

AxMultiServiceRouter<TServices, TModelKey>

Methods

chat()

chat(req: Readonly<AxChatRequest<TModelKey>>, options?: Readonly<AxAIServiceOptions>): Promise<
  | AxChatResponse
| ReadableStream<AxChatResponse>>;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/ai/multiservice.ts#L157

Delegates the chat call to the service matching the provided model key.

Parameters

ParameterType
reqReadonly<AxChatRequest<TModelKey>>
options?Readonly<AxAIServiceOptions>

Returns

Promise< | AxChatResponse | ReadableStream<AxChatResponse>>

Implementation of

AxAIService.chat


embed()

embed(req: Readonly<AxEmbedRequest<TModelKey>>, options?: Readonly<AxAIServiceOptions>): Promise<AxEmbedResponse>;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/ai/multiservice.ts#L184

Delegates the embed call to the service matching the provided embed model key.

Parameters

ParameterType
reqReadonly<AxEmbedRequest<TModelKey>>
options?Readonly<AxAIServiceOptions>

Returns

Promise<AxEmbedResponse>

Implementation of

AxAIService.embed


getFeatures()

getFeatures(model?: TModelKey): AxAIFeatures;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/ai/multiservice.ts#L248

If a model key is provided, delegate to the corresponding service’s features. Otherwise, returns a default feature set.

Parameters

ParameterType
model?TModelKey

Returns

AxAIFeatures

Implementation of

AxAIService.getFeatures


getId()

getId(): string;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/ai/multiservice.ts#L214

Returns a composite ID built from the IDs of the underlying services.

Returns

string

Implementation of

AxAIService.getId


getLastUsedChatModel()

getLastUsedChatModel(): unknown;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/ai/multiservice.ts#L144

Returns

unknown

Implementation of

AxAIService.getLastUsedChatModel


getLastUsedEmbedModel()

getLastUsedEmbedModel(): unknown;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/ai/multiservice.ts#L147

Returns

unknown

Implementation of

AxAIService.getLastUsedEmbedModel


getLastUsedModelConfig()

getLastUsedModelConfig(): undefined | AxModelConfig;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/ai/multiservice.ts#L150

Returns

undefined | AxModelConfig

Implementation of

AxAIService.getLastUsedModelConfig


getLogger()

getLogger(): AxLoggerFunction;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/ai/multiservice.ts#L333

Returns the logger from the last used service, or falls back to the first service if none has been used.

Returns

AxLoggerFunction

Implementation of

AxAIService.getLogger


getMetrics()

getMetrics(): AxAIServiceMetrics;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/ai/multiservice.ts#L292

Returns aggregated metrics from the underlying service. Uses the metrics from the last service that was used, or falls back to the first service if none has been used.

Returns

AxAIServiceMetrics

Implementation of

AxAIService.getMetrics


getModelList()

getModelList(): AxAIModelList<TModelKey>;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/ai/multiservice.ts#L230

Aggregates all available models across the underlying services.

Returns

AxAIModelList<TModelKey>

Implementation of

AxAIService.getModelList


getName()

getName(): string;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/ai/multiservice.ts#L223

Returns the name of this router.

Returns

string

Implementation of

AxAIService.getName


getOptions()

getOptions(): Readonly<AxAIServiceOptions>;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/ai/multiservice.ts#L325

Returns the options from the last used service, or falls back to the first service if none has been used.

Returns

Readonly<AxAIServiceOptions>

Implementation of

AxAIService.getOptions


setOptions()

setOptions(options: Readonly<AxAIServiceOptions>): void;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/ai/multiservice.ts#L314

Sets options on all underlying services.

Parameters

ParameterType
optionsReadonly<AxAIServiceOptions>

Returns

void

Implementation of

AxAIService.setOptions


setServiceEntry()

setServiceEntry(key: TModelKey, entry: object): void;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/ai/multiservice.ts#L353

Sets a service entry for a given key. This method is intended for testing purposes.

Parameters

ParameterTypeDescription
keyTModelKeyThe model key
entry{ description: string; embedModel?: string; isInternal?: boolean; model?: string; service: AxAIService<unknown, unknown, TModelKey>; }The service entry to set
entry.descriptionstring-
entry.embedModel?string-
entry.isInternal?boolean-
entry.model?string-
entry.serviceAxAIService<unknown, unknown, TModelKey>-

Returns

void


create()

static create<TServices>(services: TServices): AxMultiServiceRouter<TServices, ExtractAllModelKeys<TServices>>;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/ai/multiservice.ts#L134

Static factory method for type-safe multi-service router creation with automatic model key inference.

Type Parameters

Type Parameter
TServices extends readonly ( | AxAIService<unknown, unknown, string> | AxAIServiceListItem<any, any, any>)[]

Parameters

ParameterType
servicesTServices

Returns

AxMultiServiceRouter<TServices, ExtractAllModelKeys<TServices>>