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/5b28f9093bb70863b59459bb6df5062d005bce41/src/ax/ai/balance.ts#L62

Balancer that rotates through services.

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/5b28f9093bb70863b59459bb6df5062d005bce41/src/ax/ai/balance.ts#L83

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/5b28f9093bb70863b59459bb6df5062d005bce41/src/ax/ai/balance.ts#L393

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/5b28f9093bb70863b59459bb6df5062d005bce41/src/ax/ai/balance.ts#L532

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/5b28f9093bb70863b59459bb6df5062d005bce41/src/ax/ai/balance.ts#L347

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/5b28f9093bb70863b59459bb6df5062d005bce41/src/ax/ai/balance.ts#L203

Parameters

ParameterType
model?string

Returns

AxAIFeatures

Implementation of

AxAIService.getFeatures


getId()

TypeScript
getId(): string;

Defined in: https://github.com/ax-llm/ax/blob/5b28f9093bb70863b59459bb6df5062d005bce41/src/ax/ai/balance.ts#L199

Returns

string

Implementation of

AxAIService.getId


getLastUsedChatModel()

TypeScript
getLastUsedChatModel(): unknown;

Defined in: https://github.com/ax-llm/ax/blob/5b28f9093bb70863b59459bb6df5062d005bce41/src/ax/ai/balance.ts#L116

Returns

unknown

Implementation of

AxAIService.getLastUsedChatModel


getLastUsedEmbedModel()

TypeScript
getLastUsedEmbedModel(): unknown;

Defined in: https://github.com/ax-llm/ax/blob/5b28f9093bb70863b59459bb6df5062d005bce41/src/ax/ai/balance.ts#L119

Returns

unknown

Implementation of

AxAIService.getLastUsedEmbedModel


getLastUsedModelConfig()

TypeScript
getLastUsedModelConfig(): undefined | AxModelConfig;

Defined in: https://github.com/ax-llm/ax/blob/5b28f9093bb70863b59459bb6df5062d005bce41/src/ax/ai/balance.ts#L122

Returns

undefined | AxModelConfig

Implementation of

AxAIService.getLastUsedModelConfig


getLogger()

TypeScript
getLogger(): AxLoggerFunction;

Defined in: https://github.com/ax-llm/ax/blob/5b28f9093bb70863b59459bb6df5062d005bce41/src/ax/ai/balance.ts#L619

Returns

AxLoggerFunction

Implementation of

AxAIService.getLogger


getMetrics()

TypeScript
getMetrics(): AxAIServiceMetrics;

Defined in: https://github.com/ax-llm/ax/blob/5b28f9093bb70863b59459bb6df5062d005bce41/src/ax/ai/balance.ts#L260

Returns

AxAIServiceMetrics

Implementation of

AxAIService.getMetrics


getModelList()

TypeScript
getModelList(): 
  | undefined
| AxAIModelList<TModelKey>;

Defined in: https://github.com/ax-llm/ax/blob/5b28f9093bb70863b59459bb6df5062d005bce41/src/ax/ai/balance.ts#L160

Returns

| undefined | AxAIModelList<TModelKey>

Implementation of

AxAIService.getModelList


getName()

TypeScript
getName(): string;

Defined in: https://github.com/ax-llm/ax/blob/5b28f9093bb70863b59459bb6df5062d005bce41/src/ax/ai/balance.ts#L195

Returns

string

Implementation of

AxAIService.getName


getOptions()

TypeScript
getOptions(): Readonly<AxAIServiceOptions>;

Defined in: https://github.com/ax-llm/ax/blob/5b28f9093bb70863b59459bb6df5062d005bce41/src/ax/ai/balance.ts#L615

Returns

Readonly<AxAIServiceOptions>

Implementation of

AxAIService.getOptions


setOptions()

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

Defined in: https://github.com/ax-llm/ax/blob/5b28f9093bb70863b59459bb6df5062d005bce41/src/ax/ai/balance.ts#L605

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/5b28f9093bb70863b59459bb6df5062d005bce41/src/ax/ai/balance.ts#L598

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/5b28f9093bb70863b59459bb6df5062d005bce41/src/ax/ai/balance.ts#L591

Parameters

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

Returns

Promise<AxTranscriptionResponse>

Implementation of

AxAIService.transcribe


create()

TypeScript
static create<TServices>(services: TServices, options?: AxBalancerOptions<ExtractAllModelKeys<TServices>>): AxBalancer<TServices, ExtractAllModelKeys<TServices>>;

Defined in: https://github.com/ax-llm/ax/blob/5b28f9093bb70863b59459bb6df5062d005bce41/src/ax/ai/balance.ts#L110

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/5b28f9093bb70863b59459bb6df5062d005bce41/src/ax/ai/balance.ts#L129

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/5b28f9093bb70863b59459bb6df5062d005bce41/src/ax/ai/balance.ts#L150

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