Skip to content

model.request hook baseURL is ignored for models loaded through the AI SDK adapter #55984

Open

Description

@anandgupta42

Description

event.baseURL set in a model.request session hook is ignored for models loaded through the AI SDK adapter, while header changes from the same hook apply. Providers with a native route honor it. For AI SDK models route.with returns the same route (aisdk.ts#L408), so the request keeps the original baseURL. I want to choose the endpoint per request from a plugin.

Plugins

url-probe, a local plugin (below)

OpenCode version

2.0.30 (dev at eeec76b)

Steps to reproduce

  1. Save as /tmp/probe/url-probe/server.ts:
import { Plugin } from "@opencode/plugin"
export default Plugin.define({ id: "url-probe", async setup(ctx) {
  await ctx.session.hook("model.request", (e) => { e.baseURL = "https://replacement.example.invalid/v1" })
  await ctx.session.hook("http.request", (e) => { console.error("PROBE", e.request.url); e.request = new Request("data:,", e.request) })
}})
  1. In the same directory (/tmp/probe here) run npm i @ai-sdk/openai-compatible and put this in opencode.jsonc (the file:// package forces the AI SDK path): {"plugins":["./url-probe"],"providers":{"probe":{"package":"aisdk:file:///tmp/probe/node_modules/@ai-sdk/openai-compatible/dist/index.js","settings":{"baseURL":"https://original.example.invalid/v1","apiKey":"x"},"models":{"m":{"limit":{"context":200000,"output":4096}}}}}}
  2. Run opencode --print-logs run --standalone --model probe/m Hi. The log shows PROBE https://original.example.invalid/v1/chat/completions; I expected the replacement host.

Screenshot and/or share link

No response

Operating System

macOS 26 arm64

Terminal

No response

Activity

  1. opencode-agent commented on Oct 16, 2026

    @opencode-agent
    Contributor

    Thanks for the precise report. I reproduced this with your url-probe plugin and the aisdk:file:// openai-compatible provider config. On 2.0.30, opencode --print-logs run --standalone --model probe/m Hi logs PROBE https://original.example.invalid/v1/chat/completions for every request, so the baseURL set in model.request is ignored. It still happens on the latest dev (37e3912d8). The script below reproduces it (set OC_DEV=<checkout> to run from source).

    This matches your reading of the code: the AI SDK route's with returns the same route, so the override is dropped.

    Related, but not the same problem:

    Reproduction script (repro.sh)
    #!/usr/bin/env bash
    # Reproduces #55984: model.request hook's baseURL ignored for AI SDK models.
    # Usage: ./repro.sh            (uses `opencode` from PATH)
    #        OC_DEV=/path/to/repo ./repro.sh  (runs from source checkout)
    set -euo pipefail
    DIR=${DIR:-/tmp/opencode/probe}
    rm -rf "$DIR"; mkdir -p "$DIR/url-probe"
    cd "$DIR"
    cat > url-probe/server.ts <<'TS'
    import { Plugin } from "@opencode/plugin"
    export default Plugin.define({ id: "url-probe", async setup(ctx) {
      await ctx.session.hook("model.request", (e) => { e.baseURL = "https://replacement.example.invalid/v1" })
      await ctx.session.hook("http.request", (e) => { console.error("PROBE", e.request.url); e.request = new Request("data:,", e.request) })
    }})
    TS
    npm init -y >/dev/null
    npm i -s @ai-sdk/openai-compatible >/dev/null 2>&1
    cat > opencode.jsonc <<JSON
    {"plugins":["./url-probe"],"providers":{"probe":{"package":"aisdk:file://$DIR/node_modules/@ai-sdk/openai-compatible/dist/index.js","settings":{"baseURL":"https://original.example.invalid/v1","apiKey":"x"},"models":{"m":{"limit":{"context":200000,"output":4096}}}}}}
    JSON
    git init -q .
    if [ -n "${OC_DEV:-}" ]; then
      # the spawned standalone server needs the solid preload too; bun reads it from ./bunfig.toml
      echo "preload = [\"$OC_DEV/packages/tui/node_modules/@opentui/solid/scripts/preload.js\"]" > bunfig.toml
      OC=(bun --conditions=browser --preload="$OC_DEV/packages/tui/node_modules/@opentui/solid/scripts/preload.js" "$OC_DEV/packages/cli/src/index.ts")
    else
      OC=(opencode)
    fi
    "${OC[@]}" --version
    timeout 90 "${OC[@]}" --print-logs run --standalone --model probe/m Hi 2>&1 | grep -E "PROBE|error|Error" | head -20 || true

    Run it: bash repro.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions