How to Override the Default Model with a Custom LLM Provider in callLLM
You can override the default model in callLLM by supplying a custom model identifier through the model property in LLMOptions, or via the --model CLI flag when executing the run engine.
The UditAkhourii/adhd repository provides a flexible framework for LLM-powered workflows through its callLLM utility. Since callLLM acts as a thin wrapper around the Claude Agent SDK's query function, you can easily redirect requests to any compatible provider—including OpenAI, Anthropic variants, or self-hosted endpoints—by configuring the model parameter appropriately.
Understanding the Model Override Architecture
By default, callLLM forwards your request to the Claude Agent SDK, which falls back to its own default model (typically claude-3-sonnet-20240229) when no identifier is provided. The function builds query options through an internal helper that injects your custom model string directly into the SDK call.
In src/llm.ts, the callLLM function accepts an options object containing the optional model field. This field is passed through buildQueryOptions and ultimately determines which backend provider handles your request.
Programmatic Model Configuration
Direct Usage with callLLM
To override the model for a single invocation, pass the desired provider identifier via the model property:
import { callLLM } from "./llm.js";
await callLLM({
model: "my-custom-llm/v1", // ← custom provider identifier
systemPrompt: "You are a helpful assistant.",
userPrompt: "Explain the concept of monads."
});
Source: src/llm.ts (lines 17-20)
Engine-Level Configuration with RunOptions
For batch operations managed by the execution engine, configure models through the RunOptions interface defined in src/types.ts. This approach supports distinct models for generation and critique phases:
import { run } from "./engine.js";
await run({
problem: "Build a todo app.",
model: "anthropic/claude-3-sonnet-20240229", // generator
criticModel: "openai/gpt-4o-mini", // scorer & clusterer
// …other options
});
The engine routes these parameters to every callLLM invocation, with criticModel defaulting to the value of model when not explicitly set.
Source: src/engine.ts (lines 27-30)
Command-Line Model Overrides
The CLI entry point in src/cli.ts exposes the --model and --criticModel flags, allowing you to swap providers without modifying source code. These flags populate the RunOptions object before execution begins:
node ./src/cli.js run "Improve project documentation" \
--model=anthropic/claude-3-opus-20240229 \
--criticModel=openai/gpt-4o
Source: src/cli.ts (lines 141-147)
Complete Workflow Example
Combine engine configuration with custom providers to optimize both generation quality and evaluation cost:
import { run } from "./engine.js";
const result = await run({
problem: "Design a scalable chat service.",
model: "my-org/custom-llm-2026", // generator model
criticModel: "anthropic/claude-3-sonnet-20240229", // optional separate critic
framesPerRun: 4,
ideasPerFrame: 5,
topK: 3,
});
console.log(result.nonObviousPick?.text);
This pattern leverages src/engine.ts to orchestrate the full pipeline while maintaining granular control over which LLM handles each phase.
Summary
callLLMforwards themodelproperty directly to the underlying SDK viabuildQueryOptionsinsrc/llm.tsRunOptionsinsrc/types.tsexposes bothmodel(generation) andcriticModel(evaluation) fields for differentiated provider selection- CLI flags
--modeland--criticModelenable runtime overrides without code changes - Default fallback occurs when no model is specified, deferring to the SDK's internal default configuration
Frequently Asked Questions
What happens if I don't specify a model in callLLM?
If the model property is omitted from LLMOptions, the Claude Agent SDK falls back to its internal default, typically claude-3-sonnet-20240229. The callLLM function in src/llm.ts treats this field as optional and only forwards defined values.
Can I use different models for generation and evaluation?
Yes. The RunOptions interface supports parallel configuration through the model and criticModel fields. The engine passes criticModel to the scoring and clustering stages, defaulting to the main model value when not specified, as implemented in src/engine.ts.
Does callLLM support local or self-hosted LLMs?
Yes. Any model identifier string recognized by the Claude Agent SDK—including custom endpoints, local models served via compatible APIs, or private provider formats—can be passed via the model property in LLMOptions or the CLI flags.
Where is the model parameter processed in the source code?
The parameter is processed in src/llm.ts within the callLLM function, which constructs the query payload through buildQueryOptions before invoking the SDK's query method. The src/types.ts file defines the TypeScript interfaces that enforce type safety for these parameters.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →