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 } from "@elie-laloum/outpost/core";
import {
  createAnthropicModelProvider,
  createHarness,
} from "@elie-laloum/outpost/harness";

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/harness";

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/harness";

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).

For example, createOpenAIModelProvider({ apiKey, timeoutMs: 30_000 }) fails a request after thirty seconds without progress. While streaming, each complete data event other than a heartbeat restarts that timer; comments, partial frames and ping events do not. Add deadlineMs to the dispatch to bound a stream that keeps producing text.

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.

HTTP failures inspect at most 64 KiB of JSON, or the configured maxResponseBytes if smaller. Recognized error types and codes supplement the HTTP status; raw messages, prompts and arbitrary fields are not included in diagnostics. Malformed or oversized bodies retain the status-based classification. Anthropic credit and spend-limit messages are recognized as quota failures even with HTTP 400; ordinary invalid requests remain provider errors. The same bounded error inspection applies to System One decision providers. These cases are covered by local HTTP fixtures, without paid API calls.

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.

Validation at composition checks Outpost’s protocol settings, not a live catalogue of model capabilities. Anthropic reasoning: "none" means thinking: { type: "disabled" }; use it only with a model that supports disabling thinking. Opus 5.5, for example, refuses it. Lower effort is a different setting and is never silently substituted. See Anthropic thinking capabilities. OpenAI supports max at protocol level, subject to the selected model. Stateless Responses requests explicitly include encrypted reasoning; only reasoning with encrypted content is replayed.