Skip to content
FunCoding

Provider hook families

Shared replay, stream, and tool-compat family builders for provider plugins

Family builders wire the common replay, stream, and tool-compat hooks for a provider in one call. Part of the Building provider plugins guide.

Family builders

Shared helper builders now cover the most common replay/tool-compat families, so plugins usually do not need to hand-wire each hook one by one:

import { buildProviderReplayFamilyHooks } from "openclaw/plugin-sdk/provider-model-shared";
import { buildProviderStreamFamilyHooks } from "openclaw/plugin-sdk/provider-stream";
import { buildProviderToolCompatFamilyHooks } from "openclaw/plugin-sdk/provider-tools";

const GOOGLE_FAMILY_HOOKS = {
  ...buildProviderReplayFamilyHooks({ family: "google-gemini" }),
  ...buildProviderStreamFamilyHooks("google-thinking"),
  ...buildProviderToolCompatFamilyHooks("gemini"),
};

api.registerProvider({
  id: "acme-gemini-compatible",
  // ...
  ...GOOGLE_FAMILY_HOOKS,
});

Available replay families today:

FamilyWhat it wires inBundled examples
openai-compatibleShared OpenAI-style replay policy for OpenAI-compatible transports, including tool-call-id sanitation, assistant-first ordering fixes, and generic Gemini-turn validation where the transport needs itmoonshot, ollama, xai, zai
anthropic-by-modelClaude-aware replay policy chosen by modelId, so Anthropic-message transports only get Claude-specific thinking-block cleanup when the resolved model is actually a Claude idamazon-bedrock
native-anthropic-by-modelSame Claude-by-model policy as anthropic-by-model, plus tool-call-id sanitation and native Anthropic tool-use id preservation for transports that must keep vendor-native idsanthropic-vertex, clawrouter
google-geminiNative Gemini replay policy plus bootstrap replay sanitation. The shared family keeps the text-output Gemini CLI on tagged reasoning; the direct google provider overrides resolveReasoningOutputMode to native because Gemini API thinking arrives as native thought parts.google, google-gemini-cli
passthrough-geminiGemini thought-signature sanitation for Gemini models running through OpenAI-compatible proxy transports; does not enable native Gemini replay validation or bootstrap rewritesopenrouter, kilocode, opencode, opencode-go
hybrid-anthropic-openaiHybrid policy for providers that mix Anthropic-message and OpenAI-compatible model surfaces in one plugin; optional Claude-only thinking-block dropping stays scoped to the Anthropic sideminimax

Available stream families today:

FamilyWhat it wires inBundled examples
google-thinkingGemini thinking payload normalization on the shared stream pathgoogle, google-gemini-cli
kilocode-thinkingKilo reasoning wrapper on the shared proxy stream path, with kilo-auto/balanced and unsupported proxy reasoning ids skipping injected thinkingkilocode
moonshot-thinkingMoonshot binary native-thinking payload mapping from config + /think levelmoonshot
minimax-fast-modeMiniMax fast-mode model rewrite on the shared stream pathminimax, minimax-portal
openai-responses-defaultsShared native OpenAI/Codex Responses wrappers: attribution headers, /fast/serviceTier, text verbosity, native Codex web search, reasoning-compat payload shaping, and Responses context managementopenai
openrouter-thinkingOpenRouter reasoning wrapper for proxy routes, with unsupported-model/auto skips handled centrallyopenrouter
tool-stream-default-onDefault-on tool_stream wrapper for providers like Z.AI that want tool streaming unless explicitly disabledzai
SDK interfaces behind the family builders

Each family builder is composed from lower-level public helpers exported from the same package, which you can reach for when a provider needs to go off the common pattern:

For Gemini-family providers, keep the reasoning-output mode aligned with the transport. Direct Google Gemini API providers should use native reasoning output so OpenClaw consumes native thought parts without adding <think> / <final> prompt directives. Text-only Gemini CLI-style backends that parse a final JSON/text response can keep the shared google-gemini tagged contract.

transformProviderStreamMessages(stream, transformMessage) from provider-stream-shared applies a provider-owned mutation to streamed partial messages, terminal messages, and result(). It preserves the stream and event objects, event order, and iterator cancellation and error forwarding; the callback must tolerate absent message fields and repeated visits. buildAssistantMessage from provider-transport-runtime constructs native stream assistant envelopes with caller-supplied content and usage. stripTrailingAssistantPrefillMessages(payload) removes trailing assistant prefill messages while preserving terminal tool calls. Providers retain their own thinking and route predicates.

Some stream helpers stay provider-local on purpose. @openclaw/anthropic-provider keeps wrapAnthropicProviderStream, resolveAnthropicBetas, resolveAnthropicFastMode, resolveAnthropicServiceTier, and the lower-level Anthropic wrapper builders in its own public api.ts / contract-api.ts interface because they encode Claude OAuth beta handling and context1m gating. The xAI plugin similarly keeps native xAI Responses shaping in its own wrapStreamFn (/fast aliases, default tool_stream, unsupported strict-tool cleanup, xAI-specific reasoning-payload removal).

The same package-root pattern also backs @openclaw/openai-provider (provider builders, default-model helpers, realtime provider builders) and @openclaw/openrouter-provider (provider builder plus onboarding/config helpers).

Serialized Converse transport

createConverseStreamFn from openclaw/plugin-sdk/provider-stream-family reuses the Amazon Bedrock plugin's public execution artifact without loading its SDK until a stream is requested. Its ConverseProxyTransportFactory resolves one selected proxy endpoint and credential per request. The returned send callback receives the final serialized method, path, query, headers and body and returns complete response bytes, status and headers. It owns guarded HTTP dispatch, credential authority, bounds and cancellation; it must not resolve AWS credentials.

The native runtime retains replay conversion, SDK serialization, EventStream decoding, Claude delivery quarantine, usage and client cleanup. Proxy mode uses only the supplied bearer credential and one SDK attempt. Direct Bedrock streams continue using the native provider's existing auth and transport policy.