fix: prefer OPENAI_EMBEDDING_API_KEY over OPENAI_API_KEY for embeddings#933
fix: prefer OPENAI_EMBEDDING_API_KEY over OPENAI_API_KEY for embeddings#933w1ndcn wants to merge 2 commits into
Conversation
Signed-off-by: w1nd <w1ndcn@qq.com>
|
Someone is attempting to deploy a commit to the rohitg00's projects Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughThe PR enables OpenAI embedding provider to use dedicated credentials and endpoints separate from chat credentials. Environment variable documentation is expanded to show ChangesOpenAI Embedding Provider Configuration
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…g00#863) Signed-off-by: w1nd <w1ndcn@qq.com>
Closes #863
What changed
src/providers/embedding/index.tsOPENAI_API_KEYtoOpenAIEmbeddingProvider()constructor; let it resolve its own key from env vars (already done in0908d6e)src/config.tsdetectEmbeddingProvider()now also checksOPENAI_EMBEDDING_API_KEYwhen auto-detecting the embedding provider.env.exampleOPENAI_EMBEDDING_API_KEYandOPENAI_EMBEDDING_BASE_URLsrc/cli.tsOPENAI_EMBEDDING_API_KEYWhy
When
EMBEDDING_PROVIDER=openaiis used with both:OPENAI_API_KEYfor an OpenAI-compatible chat providerOPENAI_EMBEDDING_API_KEY/OPENAI_EMBEDDING_BASE_URLfor a separate local embedding endpoint (e.g. LM Studio, vLLM, Ollama)the embedding provider used
OPENAI_API_KEYinstead ofOPENAI_EMBEDDING_API_KEY, making it impossible to split chat and embedding endpoints.Root cause
Two issues:
Factory override (
src/providers/embedding/index.ts):createEmbeddingProvider()passedgetEnvVar("OPENAI_API_KEY")!as a constructor argument. Since constructor arguments take highest priority,OpenAIEmbeddingProvider's internal fallback chain (OPENAI_EMBEDDING_API_KEY→OPENAI_API_KEY) was never reached.Auto-detection gap (
src/config.ts):detectEmbeddingProvider()only checkedOPENAI_API_KEY, notOPENAI_EMBEDDING_API_KEY. If a user only set the latter (e.g. using Anthropic for LLM + local OpenAI-compatible for embeddings), the function returnednulland the embedding provider was never created at all.After the fix
API key resolution for OpenAI embeddings follows this precedence:
OPENAI_EMBEDDING_API_KEYOPENAI_API_KEYBase URL resolution follows this precedence:
OPENAI_EMBEDDING_BASE_URLOPENAI_BASE_URLAuto-detection now recognizes
OPENAI_EMBEDDING_API_KEYas a valid signal to enable theopenaiembedding provider.Reproduction
Config that was broken before this fix:
Before:
hosted-chat-keywas sent to the local embedding endpoint. LM Studio rejects it with an invalid token error.After:
local-embedding-keyis used for embeddings,hosted-chat-keyis used for chat. Each endpoint gets the correct key.Backward compatibility
OPENAI_API_KEYcontinue to work —OpenAIEmbeddingProviderfalls back to it.