Skip to content

🧳 fix: Carry Custom Endpoint Names Through Chat URLs - #15424

Open
abhishekbiswas772 wants to merge 1 commit into
danny-avila:devfrom
abhishekbiswas772:fix/endpoint-name-slash
Open

🧳 fix: Carry Custom Endpoint Names Through Chat URLs#15424
abhishekbiswas772 wants to merge 1 commit into
danny-avila:devfrom
abhishekbiswas772:fix/endpoint-name-slash

Conversation

@abhishekbiswas772

Copy link
Copy Markdown

Summary

Fixes #15270.

createPayload interpolated the endpoint name straight into the chat URL:

let server = `${EndpointURLs[s.EModelEndpoint.agents]}/${endpoint}`;

Custom endpoint names are user-defined, so a name like Company/API produces /api/agents/chat/Company/API. The slash reads as a path separator, the request stops matching the router's /:endpoint in api/server/routes/agents/chat.js, and it falls through to the catch-all handler in packages/api/src/middleware/notFound.ts — which is where the reported Endpoint not found actually comes from. It is the generic API 404, not an endpoint-resolution error, which is why the message gives no hint about the real cause.

Encoding the name keeps it a single path segment. Express matches the encoded segment and decodes req.params.endpoint back to the original value, and the endpoint the server acts on is read from the request body regardless (req.params.endpoint is never read anywhere in the codebase — the segment exists only for routing), so nothing downstream has to change.

This also aligns the call site with the encodeURIComponent convention already used throughout api-endpoints.ts.

I went with encoding rather than rejecting slashes at config-validation time, since the issue offers both and encoding keeps working configurations working. Happy to switch to validation instead if maintainers prefer that direction.

Change Type

  • Bug fix (non-breaking change which fixes an issue)

Testing

Confirmed the routing behaviour empirically against this repo's Express version before writing the fix — a raw slash reproduces the exact reported 404, and the percent-encoded form matches /:endpoint and decodes back to Company/API.

Added packages/data-provider/specs/createPayload.spec.ts:

  • builds the chat URL from a plain custom endpoint name
  • percent-encodes a slash so the name stays a single path segment
  • round-trips the encoded name back to the configured value
  • encodes other characters unsafe in a path segment (space, ?, =, #)
  • leaves the endpoint name itself untouched in the payload body
  • does not touch the assistants URL, which carries no endpoint segment

The slash and unsafe-character cases fail without the fix; the rest pass either way, confirming existing URLs are unchanged.

cd packages/data-provider && npx jest
# 36 suites, 1701 tests passed

Test Configuration:

Node.js v24.16.0, Windows. Reproduces with any custom endpoint whose name contains /.

Checklist

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • I have commented in any complex areas of my code
  • My changes do not introduce new warnings
  • I have written tests demonstrating that my changes are effective
  • Local unit tests pass with my changes

@github-actions
github-actions Bot changed the base branch from main to dev September 1, 2026 05:01
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

👋 Thanks for the contribution! LibreChat merges all changes into dev first — main only moves at release time — so this pull request's base branch was switched from main to dev automatically.

Nothing is needed from you; your commits, reviews and discussion are unchanged. If the diff now shows files you did not touch, rebase onto dev:

git remote add upstream https://github.com/danny-avila/LibreChat.git
git fetch upstream dev
git rebase upstream/dev
git push --force-with-lease

Maintainers: apply the target: main label and restore the base branch if this one genuinely belongs on main.

`createPayload` interpolated the endpoint name straight into the chat URL,
so a custom endpoint named `Company/API` produced
`/api/agents/chat/Company/API`. The slash reads as a path separator, the
request no longer matches the router's `/:endpoint`, and it falls through
to the catch-all handler, which answers `404 Endpoint not found`.

Encoding the name keeps it a single path segment. Express matches the
encoded segment and decodes it back, and the endpoint the server acts on
comes from the request body regardless, so nothing else has to change.

Closes danny-avila#15270
@danny-avila
danny-avila force-pushed the fix/endpoint-name-slash branch from 9258c1e to 0ea7400 Compare September 1, 2026 17:27
@danny-avila

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-01T17:33:47.673371Z 0ea7400 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danny-avila danny-avila changed the title fix: encode the endpoint name in the agents chat URL 🧳 fix: Carry Custom Endpoint Names Through Chat URLs Sep 1, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 0ea740002f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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.

[Bug]: Custom endpoint name containing a slash (/) causes “Endpoint not found”

2 participants