Skip to content

fix: normalize OpenAI-compatible paths with arbitrary prefixes#108

Merged
jpr5 merged 1 commit into
mainfrom
fix/compat-path-prefix
Apr 14, 2026
Merged

fix: normalize OpenAI-compatible paths with arbitrary prefixes#108
jpr5 merged 1 commit into
mainfrom
fix/compat-path-prefix

Conversation

@jpr5

@jpr5 jpr5 commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #107 — BigModel and other OpenAI-compatible providers use non-standard base URLs (e.g., /v4/chat/completions, /api/coding/paas/v4/chat/completions). aimock now normalizes any path ending in a known endpoint suffix to /v1/<endpoint>.

What changed

  • Extracted normalizeCompatPath() shared function — strips /openai/ prefix and rewrites arbitrary path prefixes to /v1/
  • Applied in both HTTP handler and WebSocket upgrade handler
  • Guards: skips /v1/ (already standard) and /v2/ (Cohere convention)
  • Mounts always dispatched before normalization (both HTTP and WS)
  • Azure deployment paths excluded via !azureDeploymentId guard
  • Metrics record the normalized path via closure
  • Debug logging when normalization fires

Supported suffixes

/chat/completions, /embeddings, /responses, /audio/speech, /audio/transcriptions, /images/generations

Test plan

  • 12 HTTP normalization tests (all 6 suffixes, /v1/ regression, /v2/ guard, /openai/ combo, negative 404)
  • 3 WebSocket normalization tests (/custom/responses, /openai/ strip, /v2/ guard)
  • All 2320 tests pass
  • Build passes
  • 4-round CR loop with 7 agents per round

🤖 Generated with Claude Code

@pkg-pr-new

pkg-pr-new Bot commented Apr 13, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@copilotkit/aimock@108

commit: daed83d

@jpr5
jpr5 force-pushed the fix/compat-path-prefix branch 9 times, most recently from 1023040 to de1253b Compare April 13, 2026 17:43
Providers like BigModel (/v4/chat/completions), DeepSeek, and others
use non-standard base URLs. Normalize any path ending in a known
endpoint suffix to /v1/<endpoint> before routing.

Closes #107
@jpr5
jpr5 force-pushed the fix/compat-path-prefix branch from de1253b to daed83d Compare April 13, 2026 17:45
@jpr5
jpr5 merged commit bbeaa99 into main Apr 14, 2026
22 checks passed
@jpr5
jpr5 deleted the fix/compat-path-prefix branch April 14, 2026 19:44
jpr5 added a commit that referenced this pull request Jul 15, 2026
## Summary

Fixes #107 — BigModel and other OpenAI-compatible providers use
non-standard base URLs (e.g., `/v4/chat/completions`,
`/api/coding/paas/v4/chat/completions`). aimock now normalizes any path
ending in a known endpoint suffix to `/v1/<endpoint>`.

### What changed

- Extracted `normalizeCompatPath()` shared function — strips `/openai/`
prefix and rewrites arbitrary path prefixes to `/v1/`
- Applied in both HTTP handler and WebSocket upgrade handler
- Guards: skips `/v1/` (already standard) and `/v2/` (Cohere convention)
- Mounts always dispatched before normalization (both HTTP and WS)
- Azure deployment paths excluded via `!azureDeploymentId` guard
- Metrics record the normalized path via closure
- Debug logging when normalization fires

### Supported suffixes

`/chat/completions`, `/embeddings`, `/responses`, `/audio/speech`,
`/audio/transcriptions`, `/images/generations`

## Test plan
- [x] 12 HTTP normalization tests (all 6 suffixes, /v1/ regression, /v2/
guard, /openai/ combo, negative 404)
- [x] 3 WebSocket normalization tests (/custom/responses, /openai/
strip, /v2/ guard)
- [x] All 2320 tests pass
- [x] Build passes
- [x] 4-round CR loop with 7 agents per round

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bigmodel openai

1 participant