feat: add OpenAI base URL override for regional endpoints#76
feat: add OpenAI base URL override for regional endpoints#76xavidop merged 1 commit intoxavidop:mainfrom
Conversation
Add support for OPENAI_BASE_URL and a --openai-base-url flag so tests can target regional OpenAI endpoints like eu.api.openai.com/v1 while keeping the default behavior unchanged. Co-authored-by: Cursor <cursoragent@cursor.com>
WalkthroughThis pull request introduces a configurable OpenAI base URL feature. A new global variable, command-line flag ( Changes
Sequence Diagram(s)sequenceDiagram
actor User
participant CLI as cmd/root.go
participant Global as global vars
participant Auth as openai/auth
participant Client as API Client
User->>CLI: Provides --openai-base-url flag<br/>(or OPENAI_BASE_URL env var)
CLI->>Global: Stores in global.OpenAIBaseURL
Note over CLI,Global: Flag parsed & bound during init()
CLI->>Auth: Calls SetOpenAIBaseURL()
Auth->>Global: Reads global.OpenAIBaseURL
Alt Env var set
Auth->>Auth: Use OPENAI_BASE_URL value
Else Env var unset
Auth->>Auth: Default to https://api.openai.com/v1
End
Auth->>Auth: Trim trailing slashes
Auth->>Global: Update global.OpenAIBaseURL
CLI->>Client: Calls API function (similarity/common)
Client->>Auth: GetChatCompletionsURL()
Auth->>Auth: Return base + /chat/completions
Auth-->>Client: Full endpoint URL
Client->>Client: Make HTTP request to configured URL
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@docs/docs/overview/authentication.md`:
- Line 13: Fix the typo in the markdown heading by replacing the incorrect
heading text "## Open AI PI Key" with the corrected "## OpenAI API Key" so the
section title reads properly; locate the heading string "## Open AI PI Key" in
the docs/overview/authentication.md content and update it to "## OpenAI API
Key".
🧹 Nitpick comments (1)
internal/openai/authentication.go (1)
30-33: Getter with side-effect:GetChatCompletionsURL()mutates global state.
GetChatCompletionsURL()callsSetOpenAIBaseURL()on every invocation, which writes toglobal.OpenAIBaseURL. While harmless in a single-threaded CLI and consistent with the existingSetOpenAIAPIKey()pattern, a reader might not expect aGet*function to mutate global state. Consider guarding the set with async.Onceor just documenting the lazy-init behavior with a brief comment.Not blocking — just a readability note.
| @@ -12,4 +12,19 @@ The base URL for the Voiceflow API is `https://<api>.<subdomain>.voiceflow.com`. | |||
|
|
|||
| ## Open AI PI Key | |||
There was a problem hiding this comment.
Typo in section heading: "Open AI PI Key" → "OpenAI API Key".
Pre-existing typo, but worth fixing since you're already editing this section.
📝 Proposed fix
-## Open AI PI Key
+## OpenAI API Key📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| ## Open AI PI Key | |
| ## OpenAI API Key |
🤖 Prompt for AI Agents
In `@docs/docs/overview/authentication.md` at line 13, Fix the typo in the
markdown heading by replacing the incorrect heading text "## Open AI PI Key"
with the corrected "## OpenAI API Key" so the section title reads properly;
locate the heading string "## Open AI PI Key" in the
docs/overview/authentication.md content and update it to "## OpenAI API Key".
Summary
OPENAI_BASE_URL--openai-base-urlfor explicit endpoint selectionhttps://api.openai.com/v1to preserve existing behavioragent-to-agentgoal evaluation andsimilarityvalidation)Why
Some environments require region-specific OpenAI endpoints (for example
https://eu.api.openai.com/v1).Without a base URL override,
voiceflow-clialways callshttps://api.openai.com/v1/chat/completions, which can fail under geography constraints.Test plan
go test ./...voiceflow test execute <suite> --openai-base-url https://eu.api.openai.com/v1OPENAI_BASE_URL=https://eu.api.openai.com/v1 voiceflow test execute <suite>Made with Cursor
Summary by CodeRabbit
New Features
--openai-base-urlflag orOPENAI_BASE_URLenvironment variable (defaults tohttps://api.openai.com/v1if not provided).Documentation