The fifth of the five harness ingredients from Agent Harness: the layer that lets one harness drive Anthropic, OpenAI, Google, xAI, Groq, Cerebras, OpenRouter, and whatever ships next month — without rewriting the loop. Pi’s pi-ai package is the reference implementation.

This page is the architectural completion of the harness cluster. It is also where the value of every prior ingredient compounds: cross-provider operations are what you get when every other ingredient does its job correctly.

Why Bother

Three pressures push every serious harness toward provider abstraction:

  1. Model churn. Sonnet 4 → 4.5 → 5; GPT-5; Gemini 2.5; new providers monthly. A harness pinned to one provider ages out within a year.
  2. Task-fit. Haiku for cheap classification, Sonnet for hard reasoning, Opus for the hardest, Gemini for million-token contexts. Even within a session you may want to switch.
  3. Lock-in risk. Your sessions, tools, skills, and workflows are encoded against the harness. If the harness is encoded against one provider, you inherit that provider’s risk.

A single-provider harness optimizes for short-term ergonomic fit; a multi-provider harness optimizes for long-term portability. The bet pi-ai makes is that portability matters more, because the portable harness also enables capabilities a single-provider harness cannot deliver at all (see “The Convergence” below).

What Actually Differs Between Providers

Not just request/response shape. The providers genuinely disagree about almost everything that matters in the loop.

Tool-call message structure

Not a small format detail — the message graph shape differs:

  • Anthropic: tool_use block inside the assistant’s content array, identified by tool_use_id. Result returns as a tool_result block inside a user-role message.
  • OpenAI: tool_calls array as a sibling field on the assistant message, identified by tool_call_id. Result returns as a separate message with role: "tool".
  • Gemini: functionCall part inside the content. Result returns as a functionResponse part.

A round-trip through the abstraction layer must canonicalize and re-emit, not just translate field names.

Stop-reason vocabulary

The thing your loop’s exit condition depends on:

ProviderLoop continuesLoop exits
Anthropicstop_reason: "tool_use""end_turn", "max_tokens", "stop_sequence"
OpenAIfinish_reason: "tool_calls""stop", "length", "content_filter"
GeminifinishReason: "STOP" (with function call present)"STOP", "MAX_TOKENS", "SAFETY"

Same loop, three vocabularies. The harness has one canonical signal; each adapter maps to it.

Streaming events

ProviderFormatTool args
AnthropicTyped SSE events (message_start, content_block_start, content_block_delta with text or input_json_delta, content_block_stop, message_delta, message_stop)Streamed as input_json_delta partial JSON
OpenAIChunks of choices[0].delta with cumulative contentStreamed as a string in tool_calls[i].function.arguments
GeminiChunks of candidates with partsOften delivered whole at the end, not streamed

Major consequence: the early-abort supervision property from Streaming in Agent Harnesses partly leaks across providers. On Anthropic and OpenAI you can detect tool-call intent before the args finish. On Gemini you frequently can’t. A clean abstraction over the message format does not abstract this away — it is a real capability difference.

Prompt caching

Directly affects the per-turn cost model from Agent Harness:

  • Anthropic: explicit cache_control blocks. Developer-controlled.
  • OpenAI: automatic prefix caching. No developer control.
  • Gemini: named cached-content objects with TTLs, created via a separate API call.

Three completely different mental models. A harness either (a) loses the optimization on providers that need explicit markers, (b) leaks the model-specific concept to the user, or (c) detects the active provider and applies the right strategy invisibly. There is no clean fourth option.

Reasoning / thinking blocks

Affects the belief layer from Session Observability and Replay:

  • Anthropic Sonnet 4.5 / Opus: opt-in thinking block with token budget; returned as a separate content block.
  • OpenAI o-series: reasoning is hidden from you but billed; only a reasoning_effort knob.
  • Gemini 2.5: thinking summaries returned alongside the answer.

The “what did the agent think?” question observability needs to answer is structurally different per provider. One returns it, one hides it, one summarizes it. The abstraction can normalize the envelope but cannot pretend the underlying capability is the same.

Usage accounting

Affects the cost meter:

  • Anthropic: input_tokens / output_tokens / cache_creation_input_tokens / cache_read_input_tokens
  • OpenAI: prompt_tokens / completion_tokens (cache fields newer)
  • Gemini: promptTokenCount / candidatesTokenCount / cachedContentTokenCount

Different fields, different pricing per provider per model. Cost calculation requires a per-provider rate table that the harness keeps current.

There are more (system-prompt placement, image encoding rules, sampling-parameter ranges, retry semantics, region-specific endpoints), but the six above are enough to establish the shape of the problem.

The Two Faces of Provider Abstraction

The abstraction must do two opposite things at once.

1. Hide what’s different where it doesn’t matter. Loop mechanics, tool-call shape, stop-reason mapping, streaming events, message format. The harness should not have to know which provider is behind the curtain. pi-ai canonicalizes the transcript into a neutral shape and translates at the edges.

2. Surface what’s different where it does matter. Caching markers, reasoning block opt-ins, model-specific knobs (reasoning_effort, thinking.budget_tokens), provider-only features (Anthropic batch API, OpenAI structured output, hosted tools). Hide them and you lose the capability. Expose them naively and you reintroduce lock-in.

Key

A provider abstraction is a contract: “you write to a canonical shape, and I’ll translate; but you must know that some features are provider-specific and will degrade or no-op on others.”
The honest version exposes both layers — a canonical core for the 90% of operations that are universal, and named provider-specific extensions for the 10% that aren’t. Pretending the 10% doesn’t exist is what makes naive multi-provider libraries unusable for real workloads.

The Convergence — What Cross-Provider Operations Buy You

Provider abstraction’s headline feature is “swap providers without rewriting,” but its real payoff is what becomes possible when the abstraction composes with the rest of the harness machinery.

Cross-provider fork

A session ran on Sonnet 4.5 yesterday. Fork at turn 12 and continue on GPT-5 today. Impossible without provider abstraction, because:

  • The stored transcript has Anthropic-shaped tool_use blocks with tool_use_ids.
  • To continue on OpenAI, every historical tool_use must be re-emitted as tool_calls with tool_call_ids, and every tool_result must become a role: "tool" message.
  • The system prompt’s tool schemas must be re-translated into OpenAI’s function: { parameters: ... } shape.

pi-ai canonicalizes the transcript at write time and translates at the wire. The fork operation from Session Observability and Replay composes with the provider adapter to produce a capability neither feature could deliver alone.

Cross-provider deterministic replay

Same fork mechanism, but instead of re-executing on a new model, you replay the original turns into a different model to see how it would have answered. “Would Haiku have caught this bug?” “How does Gemini 2.5 handle the same prompts?” This is A/B testing for models, on real workload, post-hoc — only possible because transcripts are canonical.

Comparative debugging — isolating the variable

The agent went off the rails on turn 14. Did it go off the rails because of the prompt or because of the model? Re-execute turn 14 against a different model from a fresh fork:

  • If both models go off → the prompt is the problem (bad context, bad rule, bad tool description)
  • If only the original model goes off → the model is the problem (try a stronger one, or change the prompt to compensate)

You’ve separated cause from correlation. This is one of the few moments in agent debugging where you can run a controlled experiment.

Mid-session model routing and failover

Within one session, route different turns to different models. Easy classification → Haiku. Hard reasoning → Sonnet. Long-context summarization → Gemini. The harness becomes a model router, not a model client. Pi exposes /model to switch mid-session; the canonical transcript is what makes it work without losing history.

A weaker version: provider failover. Anthropic outage → the harness transparently retries on OpenAI. Your session continues; the transcript stays coherent.

Why these compose

Each cross-provider operation needs every prior ingredient to be doing its job:

IngredientWhat it contributes
The loopProvider-neutral; same loop drives any backend
ToolsCanonical schemas that translate per-provider
ContextCaptured as-it-was (Session Observability and Replay) so you know what rules the original ran under
Sessions + branchingMake “fork from turn 12” a first-class operation
StreamingNormalized so user-side UX doesn’t change per provider
Provider adapterTranslates canonical transcript on the wire

Each is necessary. None alone delivers cross-provider replay. The harness’s value is exactly the value of these ingredients composing — which is why a maximal harness that bakes in provider-specific behavior loses this capability silently, even when it appears richer feature-by-feature.

Key

Pi’s minimalism is a strategy, not an aesthetic: minimal pieces compose. Maximal pieces don’t.

Pi’s Implementation: pi-ai

From Pi (Coding Agent): pi-ai provides a “unified LLM API: multi-provider (Anthropic, OpenAI, Google, xAI, Groq, Cerebras, OpenRouter), streaming, tool calling with TypeBox schemas, cross-provider context handoff, abort support, split tool results (LLM portion vs UI portion).”

Concretely:

  • Canonical transcript — messages stored in pi-ai’s neutral shape; provider-specific bodies are constructed at request time
  • TypeBox tool schemas — one schema definition compiled to each provider’s tool format
  • Streaming normalization — provider events translated into a single internal stream of typed deltas
  • Per-provider rate/cost tables — usage normalized to a common cost model
  • Cross-provider context handoff — the operation that makes mid-session model switching real
  • Split tool results — separates the part the LLM sees from the part the UI shows; works the same across providers
  • Abort propagation — Esc terminates the underlying HTTP stream regardless of provider

The result: the rest of pi-coding-agent (loop, sessions, slash commands, AGENTS.md, export) is written against pi-ai’s canonical interface and is therefore provider-neutral by construction.

The Honest Limits

A provider abstraction has real ceilings:

  • Lowest-common-denominator risk. Features that exist on only one provider may not be exposed (or are exposed as opt-in extensions that bind you to that provider).
  • Maintenance burden. Every new model from any provider requires updates to schemas, cost tables, streaming parsers, and capability flags.
  • Capability drift. A model upgrade on one provider may move features in or out of “universal” territory; the abstraction must keep up.
  • Leak surface. Caching, reasoning, hosted tools — these will leak. The abstraction’s job is to make the leaks named and controlled, not to pretend they don’t exist.

For most users this is a worthy trade. The alternative — pinning to one provider and rewriting when the API changes — is a worse cost paid further down the road.

Open Questions

  • Is there a “thin enough” provider abstraction that captures 95% of value with minimal leak surface, or does serious use always end up exposing provider-specific knobs?
  • How should harnesses surface capability differences (reasoning blocks, prompt caching, hosted tools) in a discoverable way without becoming a CRUD UI for every provider’s quirks?
  • Could a community-maintained registry of model capability matrices (cost, context window, supports-thinking, supports-explicit-cache) live alongside pi-ai, the way browser-compat data lives alongside MDN?
  • Are there workloads where provider lock-in is actually the right call (e.g. tight coupling to one provider’s hosted tools), and how should a harness make that choice explicit rather than accidental?