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

AxAIServiceOptions

type AxAIServiceOptions = object;

Defined in: https://github.com/ax-llm/ax/blob/05ff5bd88d050f7ba85a3fcc6eb0ed2975ad7d51/src/ax/ai/types.ts#L707

Runtime options for AI service requests.

These options control how requests are made to the AI service, including debugging, rate limiting, streaming, function calling, and extended thinking.

Example

const options: AxAIServiceOptions = {
  stream: true,
  thinkingTokenBudget: 'medium',
  debug: true
};
await gen.forward(ai, values, options);

Properties

abortSignal?

optional abortSignal: AbortSignal;

Defined in: https://github.com/ax-llm/ax/blob/05ff5bd88d050f7ba85a3fcc6eb0ed2975ad7d51/src/ax/ai/types.ts#L747

AbortSignal for cancelling in-flight requests.


contextCache?

optional contextCache: AxContextCacheOptions;

Defined in: https://github.com/ax-llm/ax/blob/05ff5bd88d050f7ba85a3fcc6eb0ed2975ad7d51/src/ax/ai/types.ts#L863

Context caching options for large prompt prefixes.

When enabled, large prompt prefixes can be cached for cost savings and lower latency on subsequent requests.

Currently supported by: Google Gemini/Vertex AI


corsProxy?

optional corsProxy: string;

Defined in: https://github.com/ax-llm/ax/blob/05ff5bd88d050f7ba85a3fcc6eb0ed2975ad7d51/src/ax/ai/types.ts#L845

CORS proxy URL for browser environments.

When running in a browser, API calls may be blocked by CORS. Specify a proxy URL to route requests through.

Example

'https://cors-anywhere.herokuapp.com/'

customLabels?

optional customLabels: Record<string, string>;

Defined in: https://github.com/ax-llm/ax/blob/05ff5bd88d050f7ba85a3fcc6eb0ed2975ad7d51/src/ax/ai/types.ts#L883

Custom labels for OpenTelemetry metrics.

These labels are merged with axGlobals.customLabels (service-level options override global settings).

Example

{ environment: 'production', feature: 'search' }

debug?

optional debug: boolean;

Defined in: https://github.com/ax-llm/ax/blob/05ff5bd88d050f7ba85a3fcc6eb0ed2975ad7d51/src/ax/ai/types.ts#L714

Enable debug logging for troubleshooting.

When true, logs detailed information about prompts, responses, and the generation pipeline. Useful for understanding AI behavior.


debugHideSystemPrompt?

optional debugHideSystemPrompt: boolean;

Defined in: https://github.com/ax-llm/ax/blob/05ff5bd88d050f7ba85a3fcc6eb0ed2975ad7d51/src/ax/ai/types.ts#L756

Hide system prompt in debug output (for cleaner logs).


examplesInSystem?

optional examplesInSystem: boolean;

Defined in: https://github.com/ax-llm/ax/blob/05ff5bd88d050f7ba85a3fcc6eb0ed2975ad7d51/src/ax/ai/types.ts#L873

Render examples/demos in the system prompt instead of as message pairs.

Message pair rendering generally produces better results.


excludeContentFromTrace?

optional excludeContentFromTrace: boolean;

Defined in: https://github.com/ax-llm/ax/blob/05ff5bd88d050f7ba85a3fcc6eb0ed2975ad7d51/src/ax/ai/types.ts#L744

Exclude message content from OpenTelemetry traces (for privacy).


fetch?

optional fetch: typeof fetch;

Defined in: https://github.com/ax-llm/ax/blob/05ff5bd88d050f7ba85a3fcc6eb0ed2975ad7d51/src/ax/ai/types.ts#L728

Custom fetch implementation (useful for proxies or custom HTTP handling).


functionCallMode?

optional functionCallMode: "auto" | "native" | "prompt";

Defined in: https://github.com/ax-llm/ax/blob/05ff5bd88d050f7ba85a3fcc6eb0ed2975ad7d51/src/ax/ai/types.ts#L780

How to handle function/tool calling.

Default

'auto'

logger?

optional logger: AxLoggerFunction;

Defined in: https://github.com/ax-llm/ax/blob/05ff5bd88d050f7ba85a3fcc6eb0ed2975ad7d51/src/ax/ai/types.ts#L750

Custom logger function for debug output.


meter?

optional meter: Meter;

Defined in: https://github.com/ax-llm/ax/blob/05ff5bd88d050f7ba85a3fcc6eb0ed2975ad7d51/src/ax/ai/types.ts#L734

OpenTelemetry meter for metrics collection.


rateLimiter?

optional rateLimiter: AxRateLimiterFunction;

Defined in: https://github.com/ax-llm/ax/blob/05ff5bd88d050f7ba85a3fcc6eb0ed2975ad7d51/src/ax/ai/types.ts#L725

Custom rate limiter function to control request throughput.


retry?

optional retry: Partial<RetryConfig>;

Defined in: https://github.com/ax-llm/ax/blob/05ff5bd88d050f7ba85a3fcc6eb0ed2975ad7d51/src/ax/ai/types.ts#L853

Retry configuration for failed requests.

Controls automatic retry behavior for transient errors (rate limits, timeouts, server errors).


sessionId?

optional sessionId: string;

Defined in: https://github.com/ax-llm/ax/blob/05ff5bd88d050f7ba85a3fcc6eb0ed2975ad7d51/src/ax/ai/types.ts#L753

Session identifier for conversation tracking and memory isolation.


showThoughts?

optional showThoughts: boolean;

Defined in: https://github.com/ax-llm/ax/blob/05ff5bd88d050f7ba85a3fcc6eb0ed2975ad7d51/src/ax/ai/types.ts#L824

Include the model’s thinking/reasoning in the output.

When true and thinkingTokenBudget is set, the model’s internal reasoning is included in the response. Useful for debugging and understanding AI behavior.

Default

false

stepIndex?

optional stepIndex: number;

Defined in: https://github.com/ax-llm/ax/blob/05ff5bd88d050f7ba85a3fcc6eb0ed2975ad7d51/src/ax/ai/types.ts#L835

Internal: Current step index for multi-step operations.


stream?

optional stream: boolean;

Defined in: https://github.com/ax-llm/ax/blob/05ff5bd88d050f7ba85a3fcc6eb0ed2975ad7d51/src/ax/ai/types.ts#L767

Enable streaming responses.

When true, the AI returns responses as a stream of chunks, enabling real-time display of generated text.


thinkingTokenBudget?

optional thinkingTokenBudget: "minimal" | "low" | "medium" | "high" | "highest" | "none";

Defined in: https://github.com/ax-llm/ax/blob/05ff5bd88d050f7ba85a3fcc6eb0ed2975ad7d51/src/ax/ai/types.ts#L808

Token budget for extended thinking (chain-of-thought reasoning).

Extended thinking allows models to “think through” complex problems before responding. Higher budgets allow deeper reasoning but cost more.

Approximate token allocations:

Provider support:

Example

// Enable medium thinking for complex reasoning
await gen.forward(ai, values, { thinkingTokenBudget: 'medium' });

timeout?

optional timeout: number;

Defined in: https://github.com/ax-llm/ax/blob/05ff5bd88d050f7ba85a3fcc6eb0ed2975ad7d51/src/ax/ai/types.ts#L741

Request timeout in milliseconds.

Default

300000 (5 minutes)

traceContext?

optional traceContext: Context;

Defined in: https://github.com/ax-llm/ax/blob/05ff5bd88d050f7ba85a3fcc6eb0ed2975ad7d51/src/ax/ai/types.ts#L759

OpenTelemetry trace context for distributed tracing.


tracer?

optional tracer: Tracer;

Defined in: https://github.com/ax-llm/ax/blob/05ff5bd88d050f7ba85a3fcc6eb0ed2975ad7d51/src/ax/ai/types.ts#L731

OpenTelemetry tracer for distributed tracing.


useExpensiveModel?

optional useExpensiveModel: "yes";

Defined in: https://github.com/ax-llm/ax/blob/05ff5bd88d050f7ba85a3fcc6eb0ed2975ad7d51/src/ax/ai/types.ts#L832

Hint to use a more capable (and expensive) model for complex tasks.

Some providers offer tiered models. Setting this to ‘yes’ requests the higher-capability tier when available.


verbose?

optional verbose: boolean;

Defined in: https://github.com/ax-llm/ax/blob/05ff5bd88d050f7ba85a3fcc6eb0ed2975ad7d51/src/ax/ai/types.ts#L722

Enable low-level HTTP request/response logging.

More verbose than debug. Shows raw HTTP traffic including headers. Useful for debugging API issues.