ax() API Structured generation APIs. typescript api api/ax build/apidocs api ax() API

ax() API

Structured generation APIs for typed programs.

Most Used

ax

Creates a type-safe AI generator from a signature string or AxSignature object.

FieldValue
Kindfunction
Formax
ReturnsAxGen<ParseSignature<T>["inputs"], ParseSignature<T>["outputs"] & string extends ThoughtKey ? object : { [P in string]?: string }> An AxGen instance that can be executed with .forward(ai, inputs)
Sourcesource

Call Shape

TypeScript
function ax<T, ThoughtKey>(signature: T, options?: Readonly<AxAIServiceOptions & object & object>): AxGen<ParseSignature<T>["inputs"], ParseSignature<T>["outputs"] & string extends ThoughtKey ? object : { [P in string]?: string }>;
TypeScript
function ax<TInput, TOutput, ThoughtKey>(signature: AxSignature<TInput, TOutput>, options?: Readonly<AxAIServiceOptions & object & object>): AxGen<TInput, TOutput & string extends ThoughtKey ? object : { [P in string]?: string }>;
TypeScript
function ax(signature: Readonly<AxSignatureConfig>, options?: Readonly<AxProgramForwardOptions<any>>): AxGen<AxGenIn, AxGenOut>;

Arguments And Options

NameTypeDescription
signatureTEither a signature string or a pre-built AxSignature object
options?Readonly<AxAIServiceOptions & object & object>Optional configuration for the generator

Examples

TypeScript
const qa = ax('question: string -> answer: string');
const result = await qa.forward(ai, { question: 'What is TypeScript?' });
console.log(result.answer);
TypeScript
const classifier = ax('text: string -> sentiment: class(positive, negative, neutral)');
const result = await classifier.forward(ai, { text: 'I love this!' });
console.log(result.sentiment); // 'positive'

Full reference

AxFunctionProcessor

TypeScript class exported by @ax-llm/ax. See the constructor, methods, and full reference below.

FieldValue
Kindclass
FormAxFunctionProcessor
Sourcesource

Call Shape

TypeScript
new AxFunctionProcessor(funcList: readonly AxFunction[]): AxFunctionProcessor;

Full reference

AxGen

TypeScript class exported by @ax-llm/ax. See the constructor, methods, and full reference below.

FieldValue
Kindclass
FormAxGen
Sourcesource

Call Shape

TypeScript
new AxGen<IN, OUT>(signature: 
  | string
  | Readonly<AxSignatureConfig>
| Readonly<AxSignature<IN & Record<string, any>, OUT>>, options?: Readonly<AxProgramForwardOptions<any>>): AxGen<IN, OUT>;

Full reference

AxGenerateError

TypeScript class exported by @ax-llm/ax. See the constructor, methods, and full reference below.

FieldValue
Kindclass
FormAxGenerateError
Sourcesource

Call Shape

TypeScript
new AxGenerateError(
   message: string, 
   details: Readonly<AxGenerateErrorDetails>, 
   options?: ErrorOptions): AxGenerateError;

Full reference

AxProgram

TypeScript class exported by @ax-llm/ax. See the constructor, methods, and full reference below.

FieldValue
Kindclass
FormAxProgram
Sourcesource

Call Shape

TypeScript
new AxProgram<IN, OUT>(signature: 
  | undefined
  | string
  | Readonly<AxSignature<Record<string, any>, Record<string, any>>>
| Readonly<AxSignatureConfig>, options?: Readonly<AxProgramOptions>): AxProgram<IN, OUT>;

Full reference

fn

Creates a fluent builder for defining callable functions/tools with typed args, return schemas, namespaces, and optional AxAgent discovery examples.

FieldValue
Kindfunction
Formfn
ReturnsAxFunctionBuilder<{ }, unknown, false>
Sourcesource

Call Shape

TypeScript
function fn<TName>(name: TName): AxFunctionBuilder<{
}, unknown, false>;

Arguments And Options

NameTypeDescription
nameTName

Full reference

Advanced / internals / full reference

AxAssertion

TypeScript interface exported by @ax-llm/ax. See the fields and full reference below.

FieldValue
Kindinterface
FormAxAssertion
Sourcesource

Call Shape

TypeScript
fn(values: T): 
  | undefined
  | string
  | boolean
| Promise<undefined | string | boolean>;

Full reference

AxAssertionError

TypeScript class exported by @ax-llm/ax. See the constructor, methods, and full reference below.

FieldValue
Kindclass
FormAxAssertionError
Sourcesource

Call Shape

TypeScript
new AxAssertionError(__namedParameters: Readonly<{
  message: string;
}>): AxAssertionError;

Full reference

AxBestOfN

TypeScript class exported by @ax-llm/ax. See the constructor, methods, and full reference below.

FieldValue
Kindclass
FormAxBestOfN
Sourcesource

Call Shape

TypeScript
new AxBestOfN<IN, OUT>(program: Readonly<AxProgrammable<IN, OUT>>, options: Readonly<AxBestOfNOptions<IN, OUT>>): AxBestOfN<IN, OUT>;

Full reference

AxBestOfNOptions

TypeScript typealias exported by @ax-llm/ax. See the full reference for complete details.

FieldValue
Kindtypealias
FormAxBestOfNOptions
Sourcesource

Call Shape

TypeScript
type AxBestOfNOptions<IN, OUT> = object;

Full reference

AxFunctionError

TypeScript class exported by @ax-llm/ax. See the constructor, methods, and full reference below.

FieldValue
Kindclass
FormAxFunctionError
Sourcesource

Call Shape

TypeScript
new AxFunctionError(fields: object[]): AxFunctionError;

Full reference

AxGenDeltaOut

TypeScript typealias exported by @ax-llm/ax. See the full reference for complete details.

FieldValue
Kindtypealias
FormAxGenDeltaOut
Sourcesource

Call Shape

TypeScript
type AxGenDeltaOut<OUT> = object;

Full reference

AxGenerateErrorDetails

TypeScript typealias exported by @ax-llm/ax. See the full reference for complete details.

FieldValue
Kindtypealias
FormAxGenerateErrorDetails
Sourcesource

Call Shape

TypeScript
type AxGenerateErrorDetails = object;

Full reference

AxGenerateResult

TypeScript typealias exported by @ax-llm/ax. See the full reference for complete details.

FieldValue
Kindtypealias
FormAxGenerateResult
Sourcesource

Call Shape

TypeScript
type AxGenerateResult<OUT> = OUT & object;

Full reference

AxGenIn

TypeScript typealias exported by @ax-llm/ax. See the full reference for complete details.

FieldValue
Kindtypealias
FormAxGenIn
Sourcesource

Call Shape

TypeScript
type AxGenIn = object;

Full reference

AxGenInput

TypeScript typealias exported by @ax-llm/ax. See the full reference for complete details.

FieldValue
Kindtypealias
FormAxGenInput
Sourcesource

Call Shape

TypeScript
type AxGenInput<T> = T extends AxGen<infer IN, any> ? IN : T extends AxSignature<infer IN2, any> ? IN2 : T extends AxSignatureBuilder<infer IN3, any> ? IN3 : T extends string ? ParseSignature<T> extends object ? IN4 : never : never;

Full reference

AxGenMetricsInstruments

TypeScript interface exported by @ax-llm/ax. See the fields and full reference below.

FieldValue
Kindinterface
FormAxGenMetricsInstruments
Sourcesource

Full reference

AxGenOut

TypeScript typealias exported by @ax-llm/ax. See the full reference for complete details.

FieldValue
Kindtypealias
FormAxGenOut
Sourcesource

Call Shape

TypeScript
type AxGenOut = object;

Full reference

AxGenOutput

TypeScript typealias exported by @ax-llm/ax. See the full reference for complete details.

FieldValue
Kindtypealias
FormAxGenOutput
Sourcesource

Call Shape

TypeScript
type AxGenOutput<T> = T extends AxGen<any, infer OUT> ? OUT : T extends AxSignature<any, infer OUT2> ? OUT2 : T extends AxSignatureBuilder<any, infer OUT3> ? OUT3 : T extends string ? ParseSignature<T> extends object ? OUT4 : never : never;

Full reference

AxGenStreamingOut

TypeScript typealias exported by @ax-llm/ax. See the full reference for complete details.

FieldValue
Kindtypealias
FormAxGenStreamingOut
Sourcesource

Call Shape

TypeScript
type AxGenStreamingOut<OUT> = AsyncGenerator<AxGenDeltaOut<OUT>, void, unknown>;

Full reference

AxProgramDemos

TypeScript typealias exported by @ax-llm/ax. See the full reference for complete details.

FieldValue
Kindtypealias
FormAxProgramDemos
Sourcesource

Call Shape

TypeScript
type AxProgramDemos<IN, OUT, ID> = object;

Full reference

AxProgramExamples

TypeScript typealias exported by @ax-llm/ax. See the full reference for complete details.

FieldValue
Kindtypealias
FormAxProgramExamples
Sourcesource

Call Shape

TypeScript
type AxProgramExamples<IN, OUT> = 
  | AxProgramDemos<IN, OUT>
  | AxProgramDemos<IN, OUT>["traces"];

Full reference

AxProgramForwardOptions

TypeScript typealias exported by @ax-llm/ax. See the full reference for complete details.

FieldValue
Kindtypealias
FormAxProgramForwardOptions
Sourcesource

Call Shape

TypeScript
type AxProgramForwardOptions<MODEL> = AxAIServiceOptions & object;

Full reference

AxProgramForwardOptionsWithModels

TypeScript typealias exported by @ax-llm/ax. See the full reference for complete details.

FieldValue
Kindtypealias
FormAxProgramForwardOptionsWithModels
Sourcesource

Call Shape

TypeScript
type AxProgramForwardOptionsWithModels<T> = AxProgramForwardOptions<AxAIServiceModelType<T>>;

Full reference

AxProgrammable

TypeScript interface exported by @ax-llm/ax. See the fields and full reference below.

FieldValue
Kindinterface
FormAxProgrammable
Sourcesource

Call Shape

TypeScript
applyOptimization(optimizedProgram: AxOptimizedProgram<OUT>): void;

Full reference

AxProgramOptions

TypeScript interface exported by @ax-llm/ax. See the fields and full reference below.

FieldValue
Kindinterface
FormAxProgramOptions
Sourcesource

Full reference

AxProgramStreamingForwardOptions

TypeScript typealias exported by @ax-llm/ax. See the full reference for complete details.

FieldValue
Kindtypealias
FormAxProgramStreamingForwardOptions
Sourcesource

Call Shape

TypeScript
type AxProgramStreamingForwardOptions<MODEL> = Omit<AxProgramForwardOptions<MODEL>, "stream">;

Full reference

AxProgramStreamingForwardOptionsWithModels

TypeScript typealias exported by @ax-llm/ax. See the full reference for complete details.

FieldValue
Kindtypealias
FormAxProgramStreamingForwardOptionsWithModels
Sourcesource

Call Shape

TypeScript
type AxProgramStreamingForwardOptionsWithModels<T> = AxProgramStreamingForwardOptions<AxAIServiceModelType<T>>;

Full reference

AxProgramTrace

TypeScript typealias exported by @ax-llm/ax. See the full reference for complete details.

FieldValue
Kindtypealias
FormAxProgramTrace
Sourcesource

Call Shape

TypeScript
type AxProgramTrace<IN, OUT> = object;

Full reference

AxProgramUsage

TypeScript typealias exported by @ax-llm/ax. See the full reference for complete details.

FieldValue
Kindtypealias
FormAxProgramUsage
Sourcesource

Call Shape

TypeScript
type AxProgramUsage = AxChatResponse["modelUsage"] & object;

Full reference

AxPromptTemplate

TypeScript class exported by @ax-llm/ax. See the constructor, methods, and full reference below.

FieldValue
Kindclass
FormAxPromptTemplate
Sourcesource

Call Shape

TypeScript
new AxPromptTemplate(
   sig: Readonly<AxSignature>, 
   options?: Readonly<AxPromptTemplateOptions>, 
   fieldTemplates?: Record<string, AxFieldTemplateFn>): AxPromptTemplate;

Full reference

AxPromptTemplateOptions

TypeScript interface exported by @ax-llm/ax. See the fields and full reference below.

FieldValue
Kindinterface
FormAxPromptTemplateOptions
Sourcesource

Full reference

AxRefine

TypeScript class exported by @ax-llm/ax. See the constructor, methods, and full reference below.

FieldValue
Kindclass
FormAxRefine
Sourcesource

Call Shape

TypeScript
new AxRefine<IN, OUT>(program: Readonly<AxProgrammable<IN, OUT>>, options: Readonly<AxRefineOptions<IN, OUT>>): AxRefine<IN, OUT>;

Full reference

AxRefineError

TypeScript class exported by @ax-llm/ax. See the constructor, methods, and full reference below.

FieldValue
Kindclass
FormAxRefineError
Sourcesource

Call Shape

TypeScript
new AxRefineError(message: string, attempts: readonly AxAttempt<any, any>[]): AxRefineError;

Full reference

AxRefineOptions

TypeScript typealias exported by @ax-llm/ax. See the full reference for complete details.

FieldValue
Kindtypealias
FormAxRefineOptions
Sourcesource

Call Shape

TypeScript
type AxRefineOptions<IN, OUT> = object;

Full reference

AxRefineStrategy

TypeScript typealias exported by @ax-llm/ax. See the full reference for complete details.

FieldValue
Kindtypealias
FormAxRefineStrategy
Sourcesource

Call Shape

TypeScript
type AxRefineStrategy = "auto" | "native-samples" | "serial";

Full reference

AxStreamingAssertion

TypeScript interface exported by @ax-llm/ax. See the fields and full reference below.

FieldValue
Kindinterface
FormAxStreamingAssertion
Sourcesource

Call Shape

TypeScript
fn(content: string, done?: boolean): 
  | undefined
  | string
  | boolean
| Promise<undefined | string | boolean>;

Full reference

AxStreamingAssertionError

TypeScript class exported by @ax-llm/ax. See the constructor, methods, and full reference below.

FieldValue
Kindclass
FormAxStreamingAssertionError
Sourcesource

Call Shape

TypeScript
new AxStreamingAssertionError(__namedParameters: Readonly<{
  message: string;
}>): AxStreamingAssertionError;

Full reference

bestOfN

TypeScript function exported by @ax-llm/ax. See the call shape, arguments, and full reference below.

FieldValue
Kindfunction
FormbestOfN
ReturnsAxBestOfN<IN, OUT>
Sourcesource

Call Shape

TypeScript
function bestOfN<IN, OUT>(program: Readonly<AxProgrammable<IN, OUT>>, options: Readonly<AxBestOfNOptions<IN, OUT>>): AxBestOfN<IN, OUT>;

Arguments And Options

NameTypeDescription
programReadonly<AxProgrammable<IN, OUT>>
optionsReadonly<AxBestOfNOptions<IN, OUT>>

Full reference

refine

TypeScript function exported by @ax-llm/ax. See the call shape, arguments, and full reference below.

FieldValue
Kindfunction
Formrefine
ReturnsAxRefine<IN, OUT>
Sourcesource

Call Shape

TypeScript
function refine<IN, OUT>(program: Readonly<AxProgrammable<IN, OUT>>, options: Readonly<AxRefineOptions<IN, OUT>>): AxRefine<IN, OUT>;

Arguments And Options

NameTypeDescription
programReadonly<AxProgrammable<IN, OUT>>
optionsReadonly<AxRefineOptions<IN, OUT>>

Full reference

Full Reference

Open the full TypeScript reference. This page highlights the ax symbols most relevant to everyday use.

Docs