anomalyco / anomalyco/opencode
[FEATURE]: Plugins can't intercept outbound requests for AI-SDK models (http.request hook excludes the AI-SDK path)
@rekram1-node is already working on this.
Since Aug 16, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Feature hasn't been suggested before.
- I have verified this feature I'm about to request hasn't been suggested before.
Describe the enhancement you want to request
The runtime hook ctx.session.hook("http.request", (event) => { … event.request … }) lets a plugin mutate the outbound Web Request immediately before provider dispatch. Per the docs, though, it applies to native models only — AI-SDK-routed models don't pass through it:
From https://opencode.ai/v2/docs/build/plugins:
"HTTP hooks can modify requests and responses. They apply to native models; AI SDK models do not currently pass through these hooks. Request and response bodies are one-shot streams."
The separate ctx.aisdk.hook("sdk" | "language", …) capability covers the AI-SDK seam but exposes only the SDK/model objects, not the outbound HTTP request/body. So for any provider configured with a custom OpenAI-compatible baseURL (self-hosted proxies, gateways like a LiteLLM/router layer, local model servers) — all of which route through the AI SDK — a plugin currently cannot inspect or rewrite the outbound request at all.
Why it matters
This is the same motivation as #19425 ("pre/post API call hooks … for secret redaction and exfiltration prevention"), but for the AI-SDK path that the shipped hook skips:
-
Security / governance (primary). Redact secrets from outbound bodies, enforce egress policy, and audit/log exactly what leaves the machine — for self-hosted-proxy and gateway deployments, which are common in orgs that route everything through one controlled endpoint. Today none of this is possible for AI-SDK providers.
-
Payload shaping. Normalize or strip fields, inject required headers/tenant tags per
baseURL, etc. -
Request-body compression (concrete, broadly useful). Large, growing JSON contexts are re-uploaded every turn. Compressing the body + setting
Content-Encodingis a real, standardized optimization that multiple real targets already accept:- Google Vertex AI accepts
Content-Encoding: gzipongenerateContentrequest bodies (working... | gzip | curl -H "Content-Encoding: gzip"example: https://github.com/BerriAI/litellm/discussions/3967). - Cerebras Inference documents accepting compressed request bodies on
/v1/chat/completions(Content-Encoding: gzip, msgpack+gzip): https://github.com/Cerebras/inference-examples/blob/main/payload-compression/simple_example.py. - Self-hosted OpenAI-compatible servers (vLLM/FastAPI/Uvicorn-based, and proxies) can decode
gzip/zstdrequest bodies — it's a standard server capability (e.g. FastAPI gzip-request middleware pattern).
Being explicit so this doesn't overclaim: OpenAI does not support request-body compression (confirmed in that same LiteLLM thread), and Anthropic/Azure/Bedrock don't document it either. The point is not "all providers" — it's that a plugin should be able to compress where the target accepts it (Vertex, Cerebras, self-hosted proxies), scoped by
baseURL, and leave the rest untouched. On a constrained uplink a ~600 KB (≈150K-token) body is tens of seconds of pure upload wait per round-trip; JSON compresses ~5–8×. - Google Vertex AI accepts
All three use cases require the one missing capability: a plugin-reachable seam that can rewrite the outbound request (headers + body) on the AI-SDK path, scoped by target.
Ask
Let plugins intercept/rewrite the outbound request for AI-SDK-routed models — either by extending http.request/http.response dispatch to cover the AI-SDK path, or by adding an outbound-request seam to ctx.aisdk.hook (whichever fits the architecture). The event should expose the request (headers + body, replaceable) and enough model/provider/baseURL context that a plugin can scope changes to a specific endpoint and leave all other providers untouched. If this is intentionally out of scope, documenting the supported alternative would also close the gap.
Happy to test a fix end-to-end against a live Content-Encoding: zstd/gzip-accepting endpoint.
Related
Narrows #19425 and #2661 (generic pre-provider / body-rewrite hook requests) to the now-actionable gap: the hook shipped, but the AI-SDK dispatch path is excluded.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.