Skip to main content
Wire individual provider hooks when a family builder does not cover the behavior. Part of the Building provider plugins guide; start with Provider hook families for the shared builders.

Hook examples

For providers that need a token exchange before each inference call:
Set supportsSystemPromptCacheBoundary: true on a provider registration only when its createStreamFn transport understands the stable/dynamic system-prompt boundary. Use splitSystemPromptCacheBoundary from openclaw/plugin-sdk/provider-transport-runtime to checkpoint the stable prefix separately, and consume the marker before sending any payload. Use stripSystemPromptCacheBoundary when caching is disabled. By default, OpenClaw strips the marker before invoking a custom transport. For custom createStreamFn transports that accumulate JSON tool arguments, use createToolArgumentPreviewSchedule() from openclaw/plugin-sdk/llm. Create one schedule per tool call and pass the accumulated raw string’s length to it before calling parseStreamingJson. The returned function admits preview refreshes at geometric growth checkpoints, so intermediate arguments snapshots can remain unchanged while raw fragments arrive. Keep emitting every raw delta and validate the complete arguments at the transport’s terminal boundary, even when the last preview was not refreshed.
OpenClaw calls hooks in roughly this order for model/provider plugins. Most providers only use 2-3. This is not the full ProviderPlugin contract - see Internals: Provider Runtime Hooks for the complete, currently-accurate hook list and fallback notes. Compatibility-only provider fields that OpenClaw no longer calls, such as ProviderPlugin.capabilities and suppressBuiltInModel, are not listed here.Keep resolveSyntheticAuth synchronous and bounded. External process/network login checks belong in prepareSyntheticAuth, which receives the captured config, environment, and cancellation signal and returns a synthetic auth result or no result. OpenClaw retains completed availability within that preparation generation. Read-only workers receive the final provider-ref outcome (including unavailable), preserving alias precedence without rerunning external checks. Cancelled preparation must reject after cleanup, not report a missing login.reconcileLocalService is called only for a configured local service, including a healthy process reused by a restarted Gateway. Honor its abort signal and reject when reconciliation fails; OpenClaw blocks the provider request and releases the request lease.Runtime fallback notes:
  • Error classification uses the prepared provider owner or already loaded provider hooks. matchesContextOverflowError and classifyFailoverReason never trigger plugin discovery while handling an error; provider preparation owns loading those hooks.
  • normalizeConfig resolves one owning plugin per provider id (bundled providers first, then the matched runtime plugin) and calls only that hook - there is no scan across other providers. Google’s own normalizeConfig hook is what normalizes google / google-vertex / google-antigravity config entries; it is not a separate core fallback.
  • resolveConfigApiKey uses the provider hook when exposed. Amazon Bedrock keeps AWS env-marker resolution in its provider plugin; runtime auth itself still uses the AWS SDK default chain when configured with auth: "aws-sdk".
  • resolveThinkingProfile(ctx) receives the selected provider, modelId, optional merged reasoning catalog hint, and optional merged model compat facts. Use compat only to select the provider’s thinking UI/profile.
  • normalizeResolvedModel(ctx) can set compactionThinkingDefault on the returned ProviderRuntimeModel when the provider has a preferred embedded-summary effort. This is prepared runtime metadata, not an operator setting or catalog field. Explicit agents.defaults.compaction.thinkingLevel takes precedence; otherwise the host uses this preference and then low. The chosen effort is still clamped to the actual compaction candidate.
  • resolveSystemPromptContribution lets a provider inject cache-aware system-prompt guidance for a model family. Prefer it over the legacy plugin-wide before_prompt_build hook when the behavior belongs to one provider/model family and should preserve the stable/dynamic cache split.
Bundled and trusted official provider policies can use resolveEffortThinkingProfile(compat?.supportedReasoningEfforts) from the private openclaw/plugin-sdk/provider-thinking-runtime helper. It accepts exact off, minimal, low, medium, high, xhigh, and max values, maps none to off, and prepends off while preserving the first occurrence of each remaining level. The default preference is medium, high, low, then off. Missing, null, or empty metadata returns undefined; a nonempty list without supported values returns an off-only profile. Keep model-specific overrides and API fallbacks in the provider policy.Bundled and trusted official plugins can also export resolveToolSearchMode(ctx) from their lightweight provider-policy-api artifact. The context contains the final provider, modelId, api, and optional baseUrl; its type is exported from openclaw/plugin-sdk/provider-model-types. Return "tools" to prefer structured Tool Search, false to veto the managed-local-service default, or undefined to leave that decision to the host. The host records the result on the resolved runtime model rather than writing configuration. Explicit tools.toolSearch settings take precedence. This hook changes schema exposure, not tool permissions or availability.resolveFastModeSupport(ctx) can be exported from the same policy artifact and registered on the provider. Return false only for a confirmed no-op Fast choice, true for an applicable local request mapping, or undefined when facts are missing. ProviderFastModePolicyContext carries the selected model, route, auth mode, runtime, request parameters and transport policy; credentials are not included. Share the policy with request construction. The host publishes only supportsFastMode, preserving unknown behavior and clearing saved preferences. This describes local applicability, not upstream entitlement or fulfillment, and does not reject /fast commands.