Skip to content

feat: add OpenAI base URL override for regional endpoints#76

Merged
xavidop merged 1 commit intoxavidop:mainfrom
MichaelFBA:feat/openai-base-url-override
Feb 16, 2026
Merged

feat: add OpenAI base URL override for regional endpoints#76
xavidop merged 1 commit intoxavidop:mainfrom
MichaelFBA:feat/openai-base-url-override

Conversation

@MichaelFBA
Copy link
Contributor

@MichaelFBA MichaelFBA commented Feb 16, 2026

Summary

  • add support for overriding OpenAI API base URL via OPENAI_BASE_URL
  • add a new CLI flag --openai-base-url for explicit endpoint selection
  • default to https://api.openai.com/v1 to preserve existing behavior
  • apply override to both OpenAI call paths used by tests (agent-to-agent goal evaluation and similarity validation)
  • document the new option in authentication docs with EU endpoint example

Why

Some environments require region-specific OpenAI endpoints (for example https://eu.api.openai.com/v1).
Without a base URL override, voiceflow-cli always calls https://api.openai.com/v1/chat/completions, which can fail under geography constraints.

Test plan

  • run go test ./...
  • manual verification with defaults (no override): existing behavior remains unchanged
  • manual verification with override:
    • voiceflow test execute <suite> --openai-base-url https://eu.api.openai.com/v1
    • or OPENAI_BASE_URL=https://eu.api.openai.com/v1 voiceflow test execute <suite>

Made with Cursor

Summary by CodeRabbit

  • New Features

    • Added support for configuring a custom OpenAI API base URL via the --openai-base-url flag or OPENAI_BASE_URL environment variable (defaults to https://api.openai.com/v1 if not provided).
  • Documentation

    • Updated authentication guide with instructions for overriding the OpenAI API base URL.

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>
@MichaelFBA MichaelFBA requested a review from xavidop as a code owner February 16, 2026 10:45
@coderabbitai
Copy link

coderabbitai bot commented Feb 16, 2026

Walkthrough

This pull request introduces a configurable OpenAI base URL feature. A new global variable, command-line flag (--openai-base-url), and environment variable support (OPENAI_BASE_URL) are added, with two new functions managing the URL lifecycle. Hardcoded OpenAI API URLs are replaced with dynamic lookups across the codebase.

Changes

Cohort / File(s) Summary
Configuration Setup
cmd/root.go, internal/global/vars.go
Introduces persistent flag --openai-base-url and new global variable OpenAIBaseURL to store the configured base URL.
URL Management
internal/openai/authentication.go
Adds SetOpenAIBaseURL() to initialize base URL from environment or use default (https://api.openai.com/v1), and GetChatCompletionsURL() to return the full chat completions endpoint.
URL Endpoint Consolidation
pkg/openai/similarity.go, pkg/test/common.go
Replaces hardcoded OpenAI API URLs with centralized calls to GetChatCompletionsURL().
Execution Integration
cmd/test/execute.go
Calls SetOpenAIBaseURL() during test execution to initialize the configured base URL.
Documentation
docs/docs/overview/authentication.md
Documents the new --openai-base-url flag and OPENAI_BASE_URL environment variable with usage examples and default behavior.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Whiskers twitch with glee,
Base URLs now flow so free,
Flags and env vars align,
Config magic, oh so fine!
OpenAI calls centralized with care. 🌟

🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main feature addition: enabling OpenAI base URL overrides for regional endpoints.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() calls SetOpenAIBaseURL() on every invocation, which writes to global.OpenAIBaseURL. While harmless in a single-threaded CLI and consistent with the existing SetOpenAIAPIKey() pattern, a reader might not expect a Get* function to mutate global state. Consider guarding the set with a sync.Once or 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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

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.

Suggested change
## 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".

@xavidop xavidop merged commit c569e3e into xavidop:main Feb 16, 2026
9 checks passed
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.

2 participants