AxBalancer
Defined in: https://github.com/ax-llm/ax/blob/e690b4823b8309e258594064abe941d4cff6ef89/src/ax/ai/balance.ts#L108
Provider balancer with ordered failover by default and opt-in adaptive routing for chat requests.
Type Parameters
| Type Parameter | Default type |
|---|---|
TServices extends readonly AxAIService<any, any, any>[] | readonly AxAIService[] |
TModelKey | ExtractAllModelKeys<TServices> |
Implements
AxAIService<unknown,unknown,TModelKey>
Constructors
Constructor
new AxBalancer<TServices, TModelKey>(services: TServices, options?: AxBalancerOptions<TModelKey>): AxBalancer<TServices, TModelKey>;Defined in: https://github.com/ax-llm/ax/blob/e690b4823b8309e258594064abe941d4cff6ef89/src/ax/ai/balance.ts#L136
Parameters
| Parameter | Type |
|---|---|
services | TServices |
options? | AxBalancerOptions<TModelKey> |
Returns
AxBalancer<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/e690b4823b8309e258594064abe941d4cff6ef89/src/ax/ai/balance.ts#L1031
Parameters
| Parameter | Type |
|---|---|
req | Readonly<AxChatRequest<TModelKey>> |
options? | Readonly<AxAIServiceOptions> |
Returns
Promise<
| AxChatResponse
| ReadableStream<AxChatResponse>>
Implementation of
embed()
embed(req: Readonly<AxEmbedRequest<TModelKey>>, options?: Readonly<AxAIServiceOptions>): Promise<AxEmbedResponse>;Defined in: https://github.com/ax-llm/ax/blob/e690b4823b8309e258594064abe941d4cff6ef89/src/ax/ai/balance.ts#L1144
Parameters
| Parameter | Type |
|---|---|
req | Readonly<AxEmbedRequest<TModelKey>> |
options? | Readonly<AxAIServiceOptions> |
Returns
Promise<AxEmbedResponse>
Implementation of
getEstimatedCost()
getEstimatedCost(modelUsage?: AxModelUsage): number;Defined in: https://github.com/ax-llm/ax/blob/e690b4823b8309e258594064abe941d4cff6ef89/src/ax/ai/balance.ts#L456
Parameters
| Parameter | Type |
|---|---|
modelUsage? | AxModelUsage |
Returns
number
Implementation of
getFeatures()
getFeatures(model?: string): AxAIFeatures;Defined in: https://github.com/ax-llm/ax/blob/e690b4823b8309e258594064abe941d4cff6ef89/src/ax/ai/balance.ts#L263
Parameters
| Parameter | Type |
|---|---|
model? | string |
Returns
Implementation of
getId()
getId(): string;Defined in: https://github.com/ax-llm/ax/blob/e690b4823b8309e258594064abe941d4cff6ef89/src/ax/ai/balance.ts#L259
Returns
string
Implementation of
getLastUsedChatModel()
getLastUsedChatModel(): unknown;Defined in: https://github.com/ax-llm/ax/blob/e690b4823b8309e258594064abe941d4cff6ef89/src/ax/ai/balance.ts#L176
Returns
unknown
Implementation of
AxAIService.getLastUsedChatModel
getLastUsedEmbedModel()
getLastUsedEmbedModel(): unknown;Defined in: https://github.com/ax-llm/ax/blob/e690b4823b8309e258594064abe941d4cff6ef89/src/ax/ai/balance.ts#L179
Returns
unknown
Implementation of
AxAIService.getLastUsedEmbedModel
getLastUsedModelConfig()
getLastUsedModelConfig(): undefined | AxModelConfig;Defined in: https://github.com/ax-llm/ax/blob/e690b4823b8309e258594064abe941d4cff6ef89/src/ax/ai/balance.ts#L182
Returns
undefined | AxModelConfig
Implementation of
AxAIService.getLastUsedModelConfig
getLogger()
getLogger(): AxLoggerFunction;Defined in: https://github.com/ax-llm/ax/blob/e690b4823b8309e258594064abe941d4cff6ef89/src/ax/ai/balance.ts#L1230
Returns
Implementation of
getMetrics()
getMetrics(): AxAIServiceMetrics;Defined in: https://github.com/ax-llm/ax/blob/e690b4823b8309e258594064abe941d4cff6ef89/src/ax/ai/balance.ts#L369
Returns
Implementation of
getModelList()
getModelList():
| undefined
| AxAIModelList<TModelKey>;Defined in: https://github.com/ax-llm/ax/blob/e690b4823b8309e258594064abe941d4cff6ef89/src/ax/ai/balance.ts#L220
Returns
| undefined
| AxAIModelList<TModelKey>
Implementation of
getName()
getName(): string;Defined in: https://github.com/ax-llm/ax/blob/e690b4823b8309e258594064abe941d4cff6ef89/src/ax/ai/balance.ts#L255
Returns
string
Implementation of
getOptions()
getOptions(): Readonly<AxAIServiceOptions>;Defined in: https://github.com/ax-llm/ax/blob/e690b4823b8309e258594064abe941d4cff6ef89/src/ax/ai/balance.ts#L1226
Returns
Readonly<AxAIServiceOptions>
Implementation of
openChatSession()
openChatSession(req: Readonly<AxChatRequest<TModelKey>>, options?: Readonly<AxAIServiceOptions>): Promise<AxChatSession>;Defined in: https://github.com/ax-llm/ax/blob/e690b4823b8309e258594064abe941d4cff6ef89/src/ax/ai/balance.ts#L1017
Parameters
| Parameter | Type |
|---|---|
req | Readonly<AxChatRequest<TModelKey>> |
options? | Readonly<AxAIServiceOptions> |
Returns
Promise<AxChatSession>
Implementation of
resolveChatService()
resolveChatService(req: Readonly<AxChatRequest<TModelKey>>, options?: Readonly<AxAIServiceOptions>): Promise<{
model?: string;
service: Readonly<AxAIService<unknown, unknown, any>>;
}>;Defined in: https://github.com/ax-llm/ax/blob/e690b4823b8309e258594064abe941d4cff6ef89/src/ax/ai/balance.ts#L1001
Resolve a provider before a controlled/tool run; the returned service is pinned.
Parameters
| Parameter | Type |
|---|---|
req | Readonly<AxChatRequest<TModelKey>> |
options? | Readonly<AxAIServiceOptions> |
Returns
Promise<{
model?: string;
service: Readonly<AxAIService<unknown, unknown, any>>;
}>
Implementation of
AxAIService.resolveChatService
setOptions()
setOptions(options: Readonly<AxAIServiceOptions>): void;Defined in: https://github.com/ax-llm/ax/blob/e690b4823b8309e258594064abe941d4cff6ef89/src/ax/ai/balance.ts#L1216
Parameters
| Parameter | Type |
|---|---|
options | Readonly<AxAIServiceOptions> |
Returns
void
Implementation of
speak()
speak(req: Readonly<AxSpeechRequest<TModelKey>>, options?: Readonly<AxAIServiceOptions>): Promise<AxChatAudioOutput>;Defined in: https://github.com/ax-llm/ax/blob/e690b4823b8309e258594064abe941d4cff6ef89/src/ax/ai/balance.ts#L1209
Parameters
| Parameter | Type |
|---|---|
req | Readonly<AxSpeechRequest<TModelKey>> |
options? | Readonly<AxAIServiceOptions> |
Returns
Promise<AxChatAudioOutput>
Implementation of
transcribe()
transcribe(req: Readonly<AxTranscriptionRequest<TModelKey>>, options?: Readonly<AxAIServiceOptions>): Promise<AxTranscriptionResponse>;Defined in: https://github.com/ax-llm/ax/blob/e690b4823b8309e258594064abe941d4cff6ef89/src/ax/ai/balance.ts#L1202
Parameters
| Parameter | Type |
|---|---|
req | Readonly<AxTranscriptionRequest<TModelKey>> |
options? | Readonly<AxAIServiceOptions> |
Returns
Promise<AxTranscriptionResponse>
Implementation of
validateChatRequest()
validateChatRequest(req: Readonly<AxChatRequest<TModelKey>>, options?: Readonly<AxAIServiceOptions>): void;Defined in: https://github.com/ax-llm/ax/blob/e690b4823b8309e258594064abe941d4cff6ef89/src/ax/ai/balance.ts#L526
Check request compatibility without network calls, credentials, or state changes.
Parameters
| Parameter | Type |
|---|---|
req | Readonly<AxChatRequest<TModelKey>> |
options? | Readonly<AxAIServiceOptions> |
Returns
void
Implementation of
AxAIService.validateChatRequest
create()
static create<TServices>(services: TServices, options?: AxBalancerOptions<ExtractAllModelKeys<TServices>>): AxBalancer<TServices, ExtractAllModelKeys<TServices>>;Defined in: https://github.com/ax-llm/ax/blob/e690b4823b8309e258594064abe941d4cff6ef89/src/ax/ai/balance.ts#L170
Static factory method for type-safe balancer creation with automatic model key inference.
Type Parameters
| Type Parameter |
|---|
TServices extends readonly AxAIService<any, any, any>[] |
Parameters
| Parameter | Type |
|---|---|
services | TServices |
options? | AxBalancerOptions<ExtractAllModelKeys<TServices>> |
Returns
AxBalancer<TServices, ExtractAllModelKeys<TServices>>
inputOrderComparator()
static inputOrderComparator(): number;Defined in: https://github.com/ax-llm/ax/blob/e690b4823b8309e258594064abe941d4cff6ef89/src/ax/ai/balance.ts#L189
Service comparator that respects the input order of services.
Returns
number
metricComparator()
static metricComparator<TModelKey>(a: AxAIService<unknown, unknown, TModelKey>, b: AxAIService<unknown, unknown, TModelKey>): number;Defined in: https://github.com/ax-llm/ax/blob/e690b4823b8309e258594064abe941d4cff6ef89/src/ax/ai/balance.ts#L210
Service comparator that sorts services by cost.
Type Parameters
| Type Parameter | Default type |
|---|---|
TModelKey | string |
Parameters
| Parameter | Type |
|---|---|
a | AxAIService<unknown, unknown, TModelKey> |
b | AxAIService<unknown, unknown, TModelKey> |
Returns
number