Model and Adapters
The Model interface and bundled adapters — OpenAICompatibleModel, AnthropicModel, OpenRouterModel, VercelGatewayModel, StaticModel.
Model interface
Every adapter implements:
import type {
Model,
InferenceRequest,
InferenceResponse,
StreamChunk,
ModelCallOptions
} from "@maniac-ai/agents";
interface Model {
readonly id: string;
readonly slug: string;
infer(req: InferenceRequest, opts?: ModelCallOptions): Promise<InferenceResponse>;
stream(req: InferenceRequest, opts?: ModelCallOptions): AsyncIterable<StreamChunk>;
}ModelCallOptions accepts signal?: AbortSignal for cooperative cancellation.
InferenceRequest carries messages, tools, max_tokens, temperature, top_p, reasoning, and response_format ("text" | "json").
InferenceResponse includes content (string or ContentPart[]), tool_calls, usage, finish_reason, and optional reasoning text.
Model catalog
Adapters that support discovery implement listModels() via the SupportsModelCatalog interface:
import { supportsModelCatalog } from "@maniac-ai/agents";
if (supportsModelCatalog(model)) {
const specs = await model.listModels();
}Use supportsModelCatalog() for feature detection. Adapters without catalogs throw ModelCatalogUnsupportedError.
Adapter matrix
Import bundled adapters from @maniac-ai/agents or @maniac-ai/agents/inference/adapters:
| Adapter | Default API key env | Notes |
|---|---|---|
OpenAICompatibleModel | OPENAI_API_KEY | Any OpenAI chat-completions-compatible endpoint; set baseUrl for local proxies |
AnthropicModel | ANTHROPIC_API_KEY | Native Messages API — streaming, tool use, extended thinking, prompt-cache passthrough |
OpenRouterModel | OPENROUTER_API_KEY | OpenRouter-normalized routing; reads message.reasoning variants |
VercelGatewayModel | AI_GATEWAY_API_KEY | Vercel AI Gateway; falls back to VERCEL_OIDC_TOKEN |
StaticModel | — | Deterministic scripted responses for tests |
OpenAI-compatible
import { OpenAICompatibleModel } from "@maniac-ai/agents";
const model = new OpenAICompatibleModel({
slug: "gpt-4o-mini",
baseUrl: process.env.OPENAI_BASE_URL, // optional
apiKey: process.env.OPENAI_API_KEY // optional — reads env by default
});Strips cache_control on multimodal parts with a one-time warning (Anthropic forwards it natively).
Anthropic
import { AnthropicModel } from "@maniac-ai/agents/inference/adapters";
const model = new AnthropicModel({
slug: "claude-sonnet-4-20250514"
});When extended thinking is enabled, the adapter bumps max_tokens above budget_tokens (Anthropic requires max_tokens > budget_tokens).
OpenRouter
import { OpenRouterModel } from "@maniac-ai/agents";
const model = new OpenRouterModel({
slug: "openai/gpt-4o-mini"
});Vercel Gateway
import { VercelGatewayModel } from "@maniac-ai/agents/inference/adapters";
const model = new VercelGatewayModel({
slug: "openai/gpt-4o-mini"
});Custom adapters
Subclass BaseModel from @maniac-ai/agents/inference and implement infer / stream. Use mergeStreamChunks to fold streaming deltas into a final InferenceResponse.
Testing with StaticModel
import { StaticModel } from "@maniac-ai/agents";
const model = new StaticModel([
{
content: "Hello!",
usage: { prompt: 1, completion: 2 },
finish_reason: "stop",
tool_calls: []
}
]);StaticModel replays responses in order — ideal for unit tests without network calls.