AxBalancer Generated TypeScript API reference. typescript api api/reference build/apidocs/Class.AxBalancer.md class AxBalancer

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 ParameterDefault type
TServices extends readonly AxAIService<any, any, any>[]readonly AxAIService[]
TModelKeyExtractAllModelKeys<TServices>

Implements

Constructors

Constructor

TypeScript
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

ParameterType
servicesTServices
options?AxBalancerOptions<TModelKey>

Returns

AxBalancer<TServices, TModelKey>

Methods

chat()

TypeScript
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

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

Returns

Promise< | AxChatResponse | ReadableStream<AxChatResponse>>

Implementation of

AxAIService.chat


embed()

TypeScript
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

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

Returns

Promise<AxEmbedResponse>

Implementation of

AxAIService.embed


getEstimatedCost()

TypeScript
getEstimatedCost(modelUsage?: AxModelUsage): number;

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

Parameters

ParameterType
modelUsage?AxModelUsage

Returns

number

Implementation of

AxAIService.getEstimatedCost


getFeatures()

TypeScript
getFeatures(model?: string): AxAIFeatures;

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

Parameters

ParameterType
model?string

Returns

AxAIFeatures

Implementation of

AxAIService.getFeatures


getId()

TypeScript
getId(): string;

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

Returns

string

Implementation of

AxAIService.getId


getLastUsedChatModel()

TypeScript
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()

TypeScript
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()

TypeScript
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()

TypeScript
getLogger(): AxLoggerFunction;

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

Returns

AxLoggerFunction

Implementation of

AxAIService.getLogger


getMetrics()

TypeScript
getMetrics(): AxAIServiceMetrics;

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

Returns

AxAIServiceMetrics

Implementation of

AxAIService.getMetrics


getModelList()

TypeScript
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

AxAIService.getModelList


getName()

TypeScript
getName(): string;

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

Returns

string

Implementation of

AxAIService.getName


getOptions()

TypeScript
getOptions(): Readonly<AxAIServiceOptions>;

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

Returns

Readonly<AxAIServiceOptions>

Implementation of

AxAIService.getOptions


openChatSession()

TypeScript
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

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

Returns

Promise<AxChatSession>

Implementation of

AxAIService.openChatSession


resolveChatService()

TypeScript
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

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

Returns

Promise<{ model?: string; service: Readonly<AxAIService<unknown, unknown, any>>; }>

Implementation of

AxAIService.resolveChatService


setOptions()

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

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

Parameters

ParameterType
optionsReadonly<AxAIServiceOptions>

Returns

void

Implementation of

AxAIService.setOptions


speak()

TypeScript
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

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

Returns

Promise<AxChatAudioOutput>

Implementation of

AxAIService.speak


transcribe()

TypeScript
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

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

Returns

Promise<AxTranscriptionResponse>

Implementation of

AxAIService.transcribe


validateChatRequest()

TypeScript
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

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

Returns

void

Implementation of

AxAIService.validateChatRequest


create()

TypeScript
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

ParameterType
servicesTServices
options?AxBalancerOptions<ExtractAllModelKeys<TServices>>

Returns

AxBalancer<TServices, ExtractAllModelKeys<TServices>>


inputOrderComparator()

TypeScript
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()

TypeScript
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 ParameterDefault type
TModelKeystring

Parameters

ParameterType
aAxAIService<unknown, unknown, TModelKey>
bAxAIService<unknown, unknown, TModelKey>

Returns

number

Docs