Skip to content

fix(agent): append /v1 to custom openai-compatible base URLs (#4600)#4617

Open
devorun wants to merge 1 commit into
NousResearch:mainfrom
devorun:patch-29
Open

fix(agent): append /v1 to custom openai-compatible base URLs (#4600)#4617
devorun wants to merge 1 commit into
NousResearch:mainfrom
devorun:patch-29

Conversation

@devorun

@devorun devorun commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Description

This PR resolves an issue where custom OpenAI-compatible base URLs (e.g., https://api.x.ai) were dropping the required /v1 path segment during chat_completions API calls, leading to 404 upstream errors.

Fixes #4600

Root Cause

The AIAgent initialization explicitly passed the user-provided base_url directly into client_kwargs. The underlying openai python client strictly appends the endpoint (like chat/completions) directly to the base URL. If the user didn't manually include /v1 at the end of their OPENAI_BASE_URL, the resulting upstream path became /chat/completions instead of /v1/chat/completions, which breaks standard OpenAI-compatible providers (xAI, vLLM, Ollama, etc.).

Changes

  • Intercepts the base_url right before the openai client is constructed.
  • Strips any trailing slashes and checks if the URL ends with /v1.
  • Automatically appends /v1/ if it's missing.
  • Scoped strictly to api_mode == "chat_completions".
  • Safely excluded custom-routed providers like copilot-acp and openrouter to prevent side effects.

Related Issue

Fixes #

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

How to Test

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform:

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

For New Skills

  • This skill is broadly useful to most users (if bundled) — see Contributing Guide
  • SKILL.md follows the standard format (frontmatter, trigger conditions, steps, pitfalls)
  • No external dependencies that aren't already available (prefer stdlib, curl, existing Hermes tools)
  • I've tested the skill end-to-end: hermes --toolsets skills -q "Use the X skill to do Y"

Screenshots / Logs

@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent loop, run_agent.py, prompt builder P2 Medium — degraded but workaround exists labels May 1, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #4618 — both fix #4600 by appending /v1 to custom base URLs.

@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #4618 — both fix #4600 by appending /v1 to custom base URLs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Custom OPENAI_BASE_URL drops /v1 on chat completions for OpenAI-compatible endpoints

2 participants