Maniac Docs
Inference

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:

AdapterDefault API key envNotes
OpenAICompatibleModelOPENAI_API_KEYAny OpenAI chat-completions-compatible endpoint; set baseUrl for local proxies
AnthropicModelANTHROPIC_API_KEYNative Messages API — streaming, tool use, extended thinking, prompt-cache passthrough
OpenRouterModelOPENROUTER_API_KEYOpenRouter-normalized routing; reads message.reasoning variants
VercelGatewayModelAI_GATEWAY_API_KEYVercel AI Gateway; falls back to VERCEL_OIDC_TOKEN
StaticModelDeterministic 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.

On this page