fix(openai_compat): improve prompt_cache_key host matching#1387
Merged
yinwm merged 2 commits intosipeed:mainfrom Mar 11, 2026
Merged
Conversation
Azure OpenAI (*.openai.azure.com) also supports prompt_cache_key, so extend the allowlist to match Azure endpoints alongside api.openai.com. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Replace strings.Contains with url.Parse + exact host comparison to prevent false positives from proxy URLs or path segments. Extract chatWithCacheKey test helper to reduce duplication. Add edge-case tests for proxy URLs, empty strings, and malformed input. Co-Authored-By: Claude Opus 4.6 <[email protected]>
yinwm
approved these changes
Mar 11, 2026
Collaborator
yinwm
left a comment
There was a problem hiding this comment.
LGTM! The changes improve the robustness of prompt_cache_key host matching and add Azure OpenAI support.
Key improvements:
- Uses
url.Parse()+Hostname()instead ofstrings.Contains()to prevent false positives from proxy URLs - Adds Azure OpenAI (
*.openai.azure.com) support - Good test coverage for edge cases (proxy URLs, empty strings, malformed input)
Thanks for the contribution!
This was referenced Mar 12, 2026
dj-oyu
pushed a commit
to dj-oyu/picoclaw
that referenced
this pull request
Mar 14, 2026
LGTM! The changes improve the robustness of prompt_cache_key host matching and add Azure OpenAI support. Thanks for the contribution!
dj-oyu
pushed a commit
to dj-oyu/picoclaw
that referenced
this pull request
Mar 16, 2026
LGTM! The changes improve the robustness of prompt_cache_key host matching and add Azure OpenAI support. Thanks for the contribution!
j0904
pushed a commit
to j0904/picoclaw
that referenced
this pull request
Mar 22, 2026
LGTM! The changes improve the robustness of prompt_cache_key host matching and add Azure OpenAI support. Thanks for the contribution!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #1353, addressing reviewer feedback from @yinwm:
Replaced
strings.Contains(apiBase, "api.openai.com")with properurl.Parse()+url.Hostname()matching to prevent false positives from proxy URLs(e.g.,
https://proxy.com/api.openai.com/v1would incorrectly match before this fix).Added Azure OpenAI endpoint support (
*.openai.azure.com) to the allowlist, sinceAzure OpenAI also supports
prompt_cache_key.Refactored test helper to reduce duplication in cache key test cases.
🗣️ Type of Change
🤖 AI Code Generation
AI provided the initial code draft. I reviewed, modified, and validated the changes.
🔗 Related Issue
Follow-up to #1353. Fixes #1333.
📚 Technical Context
https://platform.openai.com/docs/guides/prompt-caching
strings.Contains()is unsafe — proxy URLs likehttps://proxy.com/api.openai.com/v1would false-positive on the substring match
url.Parse()+url.Hostname()extracts the actual host for reliable matching*.openai.azure.com) supports prompt caching and was missing from theoriginal allowlist
supportsPromptCacheKey()helper keeps the logic clean and testable🧪 Test Environment
Minimax, Ollama, OpenAI, and Azure OpenAI API bases
📸 Evidence
Details
Tests added/updated:☑️ Checklist