Skip to content
Français

Connect a model API

Configure an OpenAI or Anthropic model provider for the built-in harness.

Connect a model provider to createHarness() so the built-in loop can call the model API. Then compose the harness and a model with createAgent() and pass that agent to a dispatch.

import {
  createAgent,
  createAnthropicModelProvider,
  createHarness,
} from "@elie-laloum/outpost";

export const agent = createAgent({
  model: { name: "claude-sonnet-5-5", maxOutputTokens: 16_000 },
  harness: createHarness({
    modelProvider: createAnthropicModelProvider({
      apiKey: process.env.ANTHROPIC_API_KEY ?? "",
    }),
  }),
});

Anthropic requires maxOutputTokens, hence the object form of model. Each model request is an HTTP call from your Node.js process; tools still run in the sandbox that the dispatch allocates.

baseUrl is required for OpenAI and includes the version prefix. The protocol you choose is the only one used: an error never switches to another.

import { createOpenAIModelProvider } from "@elie-laloum/outpost";

const openai = createOpenAIModelProvider({
  baseUrl: "https://api.openai.com/v1",
  api: "responses",
  apiKey: process.env.OPENAI_API_KEY ?? "",
});
FactoryapiPath added to baseUrlUse it for
createOpenAIModelProvider"chat-completions" (default)/chat/completionsOpenAI and servers that expose Chat Completions.
createOpenAIModelProvider"responses"/responsesThe OpenAI Responses API.
createAnthropicModelProvidernone/messagesThe Anthropic Messages API; baseUrl defaults to https://api.anthropic.com/v1.

createCodexHarness({ modelProvider }) is a different setting: it points the Codex CLI, inside the sandbox, at a Responses-compatible service (Codex).

Set apiKey: false for a server without authentication. The address is resolved from your host, not from the sandbox.

import { createOpenAIModelProvider } from "@elie-laloum/outpost";

const local = createOpenAIModelProvider({
  baseUrl: "http://127.0.0.1:8080/v1",
  apiKey: false,
});

Pass the model API key explicitly to the provider. These providers do not load account logins or read environment variables automatically. The key stays in your Node.js process; Authentication explains how this differs from CLI agents.

The agent’s model is a name or { name, reasoning, maxOutputTokens }. createAgent() rejects settings the provider does not support.

API reference: AgentModel.

The service still checks the model name and levels on each request.

Both providers stream. The harness emits text-delta events while the model writes, and a reasoning event when a response contains readable reasoning. Print them from observe with if (event.kind === "text-delta") process.stdout.write(event.text) (Follow progress).

API reference: OpenAIModelProviderOptions and AnthropicModelProviderOptions.

A timeout fails with code timeout. The harness streams with both providers, so a long answer that keeps arriving never times out: bound the whole turn with limits.

The harness’s cache option, on by default, asks the provider to reuse the conversation prefix between steps.

  • Anthropiccache marks the request for caching; cacheSystem: true adds a breakpoint on the harness instructions, which must then exist.
  • OpenAIOutpost sends no cache field; OpenAI caches stable prefixes on its side.
  • UsageCache reads appear in usage.cached, and Anthropic cache writes in usage.cacheCreated.

A cache hit is never guaranteed.

A provider sends each request once. When the service answers HTTP 429 with Retry-After, the error keeps that delay: a task retry waits at least that long, and a quota pause resumes at that time.

Rate limits fail with code quota; overloads, 5xx and connection failures are marked unavailable for fallback agents. Quota pauses list what counts as a quota.

Implement ModelProvider: request() returns a result, stream() and validate() are optional.

  • Reasoning is replayed only to the same provider, endpoint and model. Changing one drops it from the history.
  • baseUrl cannot contain credentials, a query or a fragment. Redirects are refused.
  • Anthropic responses with content other than text, tool calls and thinking fail with response.

API: createOpenAIModelProvider · createAnthropicModelProvider · OpenAIModelProviderOptions · AnthropicModelProviderOptions · ModelProvider · AgentModel.