Custom Providers

September 20, 2026 · View on GitHub

Extensions can register custom model providers via pi.registerProvider(). This enables:

  • Proxies - Route requests through corporate proxies or API gateways
  • Custom endpoints - Use self-hosted or private model deployments
  • OAuth/SSO - Add authentication flows for enterprise providers
  • Custom APIs - Implement streaming for non-standard LLM APIs

Where to go next

This page gets you to a first working provider extension. Each part of the job has its own page:

If you only need to add a model for an API Atomic already speaks, use Custom models instead.

Example Extensions

See these complete provider examples:

Table of Contents

Quick Reference

import type { ExtensionAPI } from "@bastani/atomic";

export default function (pi: ExtensionAPI) {
  // Override baseUrl for existing provider
  pi.registerProvider("anthropic", {
    baseUrl: "https://proxy.example.com"
  });

  // Register new provider with models
  pi.registerProvider("my-provider", {
    name: "My Provider",
    baseUrl: "https://api.example.com",
    apiKey: "$MY_API_KEY",
    api: "openai-completions",
    models: [
      {
        id: "my-model",
        name: "My Model",
        reasoning: false,
        input: ["text", "image"],
        cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
        contextWindow: 128000,
        maxTokens: 4096
      }
    ]
  });
}

The extension factory can also be async. For dynamic model discovery, fetch and register models in the factory instead of session_start. Atomic waits for the factory before startup continues, so the provider is available during interactive startup and to atomic --list-models.

Override Existing Provider

Moved to Override an existing provider.

Register New Provider

Moved to Register a provider.

Unregister Provider

Moved to Register a provider.

API Types

Moved to Register a provider.

Auth Header

Moved to Register a provider.

OAuth Support

Moved to Provider OAuth.

Dynamic model catalog refresh

Moved to Provider OAuth.

OAuthLoginCallbacks

Moved to Provider OAuth.

OAuthCredentials

Moved to Provider OAuth.

Custom Streaming API

Moved to Provider streaming API.

Stream Pattern

Moved to Provider streaming API.

Event Types

Moved to Provider streaming API.

Stop Reasons

Moved to Provider streaming API.

Content Blocks

Moved to Provider streaming API.

Tool Calls

Moved to Provider streaming API.

Usage and Cost

Moved to Provider streaming API.

Registration

Moved to Provider streaming API.

Testing Your Implementation

Test your provider/model pairs against these behaviors. The filenames below are suggested test names, not a required test suite:

TestPurpose
stream.test.tsBasic streaming, text output
tokens.test.tsToken counting and usage
abort.test.tsAbortSignal handling
empty.test.tsEmpty/minimal responses
context-overflow.test.tsContext window limits
image-limits.test.tsImage input handling
unicode-surrogate.test.tsUnicode edge cases
tool-call-without-result.test.tsTool call edge cases
image-tool-result.test.tsImages in tool results
total-tokens.test.tsTotal token calculation
cross-provider-handoff.test.tsContext handoff between providers

Run tests with your provider/model pairs to verify compatibility.

Config Reference

Moved to Provider API reference.

Model Definition Reference

Moved to Provider API reference.