@openclaw/ai is the publishable library form of Apus's model execution layer: provider-neutral message/tool/stream contracts, validation, diagnostics, event streams, an isolated runtime registry, and lazy adapters for the eight built-in API families (Anthropic Messages, OpenAI Completions, OpenAI Responses, Azure OpenAI Responses, ChatGPT/Codex Responses, Google Generative AI, Google Vertex, Mistral Conversations).

It publishes alongside the root apus package on every release, pinned to the same version. Its exact-pinned direct dependencies resolve at install time; the package ships no npm lockfile. Installing apus installs the matching @openclaw/ai automatically, and library consumers can depend on it directly without any Apus application code.

Quick start

import { createLlmRuntime } from "@openclaw/ai";
import { registerBuiltInApiProviders } from "@openclaw/ai/providers";

const runtime = createLlmRuntime();
registerBuiltInApiProviders(runtime.registry);

// `model` (a model descriptor), `messages`, and `apiKey` are supplied by you;
// see `examples/ai-chat` for concrete values.
const stream = runtime.streamSimple(model, { messages }, { apiKey });
for await (const event of stream) {
  if (event.type === "text_delta") process.stdout.write(event.delta);
}
const result = await stream.result();

A runnable version lives in the repository at examples/ai-chat.

Design contract

Subpath exports

Subpath Contents
. Contracts, createApiRegistry, createLlmRuntime, configureAiTransportHost
./providers registerBuiltInApiProviders, resetApiProviders
./types Model/message/tool/stream types
./validation Tool argument validation
./diagnostics Diagnostics contracts, transport logging, and sanitized URL formatting
./event-stream Shared EventStream implementation
./internal/* Apus-internal, no semver guarantee

Use @openclaw/ai/diagnostics for emitModelTransportDebug, formatModelTransportDebugUrl, and formatModelTransportDebugBaseUrl when you only need logging helpers. This entrypoint keeps provider transport implementations out of the import graph.