Skip to content

feat: support gemini and openai embeddings passthrough#931

Merged
ding113 merged 1 commit into
devfrom
feat/embeddings-passthrough-support
Mar 16, 2026
Merged

feat: support gemini and openai embeddings passthrough#931
ding113 merged 1 commit into
devfrom
feat/embeddings-passthrough-support

Conversation

@ding113

@ding113 ding113 commented Mar 16, 2026

Copy link
Copy Markdown
Owner

Summary

Support Gemini and OpenAI embeddings passthrough detection, treating /v1/embeddings as a standard endpoint with proper URL construction.

Problem

The proxy did not recognize:

  1. Gemini embedContent endpoints (/v1beta/models/{model}:embedContent and /v1/publishers/google/models/{model}:embedContent)
  2. OpenAI /v1/embeddings as a standard endpoint (was treated as MCP passthrough)

Additionally, buildProxyUrl() could duplicate /v1/embeddings when the provider base URL already included that suffix (similar to the issue fixed in #693 for Gemini).

Related PRs:

Solution

  1. Add embedContent action to Gemini endpoint detection patterns in format-mapper.ts
  2. Add /v1/embeddings to standard endpoint lists in endpoint-paths.ts and forwarder.ts
  3. Add /embeddings to targetEndpoints in url.ts to prevent URL duplication

All new embedding paths use passthrough behavior without protocol conversion.

Changes

Core Changes

  • src/app/v1/_lib/proxy/format-mapper.ts - Add embedContent to Gemini endpoint patterns
  • src/app/v1/_lib/proxy/endpoint-paths.ts - Add EMBEDDINGS to V1_ENDPOINT_PATHS, STANDARD_ENDPOINT_PATHS, STRICT_STANDARD_ENDPOINT_PATHS
  • src/app/v1/_lib/proxy/forwarder.ts - Add /v1/embeddings to standard endpoint arrays
  • src/app/v1/_lib/url.ts - Add /embeddings to targetEndpoints for URL deduplication

Supporting Changes

  • tests/unit/proxy/gemini-embedcontent-format.test.ts - Tests for Gemini embedContent format detection
  • tests/unit/proxy/openai-embeddings-format.test.ts - Tests for OpenAI embeddings format detection
  • tests/unit/proxy/openai-embeddings-forwarder.test.ts - Tests for OpenAI embeddings routing
  • tests/unit/app/v1/url.test.ts - Test for buildProxyUrl deduplication with embeddings

Testing

Automated Tests

  • Unit tests added for Gemini embedContent format detection
  • Unit tests added for OpenAI embeddings format detection
  • Unit tests added for OpenAI embeddings forwarding (not routed through MCP)
  • Unit tests added for buildProxyUrl embeddings deduplication

Verification Commands

```bash
bunx vitest run tests/unit/proxy/gemini-embedcontent-format.test.ts tests/unit/proxy/openai-embeddings-format.test.ts tests/unit/proxy/openai-embeddings-forwarder.test.ts tests/unit/app/v1/url.test.ts
bunx vitest run tests/unit/proxy/provider-selector-format-compatibility.test.ts -t "gemini format rejects claude provider, selects gemini"
bunx vitest run tests/unit/proxy/endpoint-path-normalization.test.ts
bunx @biomejs/biome check src/app/v1/_lib/proxy/format-mapper.ts src/app/v1/_lib/proxy/endpoint-paths.ts src/app/v1/_lib/proxy/forwarder.ts src/app/v1/_lib/url.ts tests/unit/proxy/gemini-embedcontent-format.test.ts tests/unit/proxy/openai-embeddings-format.test.ts tests/unit/proxy/openai-embeddings-forwarder.test.ts tests/unit/app/v1/url.test.ts
```

Notes

  • All new embedding paths continue to use passthrough behavior; no protocol conversion was added.
  • Full repo build/lint/typecheck/test was not run in this change; verification was targeted to the touched surface.

Checklist

  • Code follows project conventions
  • Self-review completed
  • Tests pass locally (targeted verification)
  • No breaking changes

Description enhanced by Claude AI

Greptile Summary

This PR adds passthrough support for embedding endpoints: Gemini :embedContent (via both /v1beta/models/... and /v1/publishers/google/models/...) and OpenAI-compatible /v1/embeddings. It correctly registers /v1/embeddings as a standard endpoint so it is routed through the normal proxy path rather than MCP passthrough, and updates buildProxyUrl to avoid duplicating the /embeddings suffix.

  • Gemini embedContent: Added :embedContent action to both Vertex AI and Direct API regex patterns in detectFormatByEndpoint, correctly detected as "gemini" format
  • OpenAI /v1/embeddings: Registered as a standard and strict-standard endpoint across endpoint-paths.ts, forwarder.ts, and format-mapper.ts; detected as "openai" format
  • URL deduplication: Added /embeddings to targetEndpoints in url.ts so buildProxyUrl won't double-append when the provider base URL already includes it
  • Tests: Three new test files with good coverage of format detection, endpoint classification, and forwarder routing behavior
  • Note: forwarder.ts maintains its own duplicate copies of STANDARD_ENDPOINTS and STRICT_STANDARD_ENDPOINTS rather than importing from endpoint-paths.ts — consider consolidating to prevent future drift

Confidence Score: 4/5

  • This PR is safe to merge — it adds well-tested passthrough support for embedding endpoints with no behavioral regressions to existing paths.
  • Score of 4 reflects clean, focused changes with good test coverage. Deducted one point because the duplicate endpoint lists in forwarder.ts (vs endpoint-paths.ts) increase maintenance risk, and a full repo build/lint/typecheck was not performed.
  • src/app/v1/_lib/proxy/forwarder.ts — duplicate endpoint lists that have already diverged from endpoint-paths.ts

Important Files Changed

Filename Overview
src/app/v1/_lib/proxy/endpoint-paths.ts Adds /v1/embeddings to V1_ENDPOINT_PATHS, STANDARD_ENDPOINT_PATHS, and STRICT_STANDARD_ENDPOINT_PATHS. Clean and consistent change.
src/app/v1/_lib/proxy/format-mapper.ts Extends detectFormatByEndpoint to recognize /v1/embeddings as "openai" format and :embedContent action for both Gemini Vertex AI and Direct API paths. Regex patterns are correct.
src/app/v1/_lib/proxy/forwarder.ts Adds /v1/embeddings to both local STANDARD_ENDPOINTS and STRICT_STANDARD_ENDPOINTS lists, ensuring embeddings requests are not routed via MCP passthrough. These lists duplicate endpoint-paths.ts and have already diverged for responses/compact.
src/app/v1/_lib/url.ts Adds /embeddings to targetEndpoints, enabling buildProxyUrl to detect when a base URL already contains the embeddings path and avoid duplicating it.
tests/unit/app/v1/url.test.ts Adds test verifying buildProxyUrl avoids duplicating /v1/embeddings when the base URL already contains it.
tests/unit/proxy/gemini-embedcontent-format.test.ts New test file covering Gemini :embedContent format detection for both v1beta and Vertex AI paths, plus negative cases for unknown actions and internal paths.
tests/unit/proxy/openai-embeddings-format.test.ts New test file verifying /v1/embeddings is detected as "openai" format, classified as standard and strict-standard endpoint, and not classified as raw passthrough.
tests/unit/proxy/openai-embeddings-forwarder.test.ts Integration-style test verifying /v1/embeddings requests are not routed through MCP passthrough URL. Uses internal doForward via type assertion.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Incoming Request] --> B{detectFormatByEndpoint}
    B -->|/v1/embeddings| C["openai format"]
    B -->|/v1beta/models/*:embedContent| D["gemini format"]
    B -->|/v1/publishers/google/models/*:embedContent| D
    B -->|Other paths| E[Existing routing]
    
    C --> F{Is standard endpoint?}
    F -->|Yes - /v1/embeddings in STANDARD_ENDPOINTS| G[Normal proxy path]
    F -->|No| H[MCP passthrough path]
    
    G --> I{buildProxyUrl}
    I -->|base URL ends with /embeddings| J[Skip duplicate append]
    I -->|base URL without /embeddings| K[Standard path concatenation]
    
    D --> L[Gemini passthrough handling]
Loading

Comments Outside Diff (1)

  1. src/app/v1/_lib/proxy/forwarder.ts, line 76-91 (link)

    Duplicate endpoint lists risk drift

    STANDARD_ENDPOINTS and STRICT_STANDARD_ENDPOINTS here are manually maintained copies of STANDARD_ENDPOINT_PATHS and STRICT_STANDARD_ENDPOINT_PATHS from endpoint-paths.ts. These two sources have already diverged — STRICT_STANDARD_ENDPOINT_PATHS in endpoint-paths.ts includes /v1/responses/compact, but STRICT_STANDARD_ENDPOINTS here does not. Each time a new endpoint like /v1/embeddings is added, both files must be kept in sync manually. Consider importing from endpoint-paths.ts to eliminate this duplication:

    import {
      STANDARD_ENDPOINT_PATHS,
      STRICT_STANDARD_ENDPOINT_PATHS,
    } from "./endpoint-paths";
    
    const STANDARD_ENDPOINTS = STANDARD_ENDPOINT_PATHS as readonly string[];
    const STRICT_STANDARD_ENDPOINTS = STRICT_STANDARD_ENDPOINT_PATHS as readonly string[];
    
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/app/v1/_lib/proxy/forwarder.ts
Line: 76-91

Comment:
**Duplicate endpoint lists risk drift**

`STANDARD_ENDPOINTS` and `STRICT_STANDARD_ENDPOINTS` here are manually maintained copies of `STANDARD_ENDPOINT_PATHS` and `STRICT_STANDARD_ENDPOINT_PATHS` from `endpoint-paths.ts`. These two sources have already diverged — `STRICT_STANDARD_ENDPOINT_PATHS` in `endpoint-paths.ts` includes `/v1/responses/compact`, but `STRICT_STANDARD_ENDPOINTS` here does not. Each time a new endpoint like `/v1/embeddings` is added, both files must be kept in sync manually. Consider importing from `endpoint-paths.ts` to eliminate this duplication:

```
import {
  STANDARD_ENDPOINT_PATHS,
  STRICT_STANDARD_ENDPOINT_PATHS,
} from "./endpoint-paths";

const STANDARD_ENDPOINTS = STANDARD_ENDPOINT_PATHS as readonly string[];
const STRICT_STANDARD_ENDPOINTS = STRICT_STANDARD_ENDPOINT_PATHS as readonly string[];
```

How can I resolve this? If you propose a fix, please make it concise.

Last reviewed commit: cbc3624

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly expands the proxy's capabilities by introducing explicit support for embedding endpoints from both Gemini and OpenAI. It refines how these specific API paths are recognized and processed, ensuring they are handled as standard endpoints rather than generic passthrough routes. Additionally, it includes a crucial fix to prevent URL path duplication during proxy URL construction, leading to more robust and correct routing for these new embedding services.

Highlights

  • Gemini Embeddings Support: Implemented passthrough detection for Gemini's :embedContent endpoint across both /v1beta/models/... and /v1/publishers/google/models/... paths.
  • OpenAI Embeddings Standardization: Integrated OpenAI-compatible /v1/embeddings as a standard endpoint, moving it away from being treated as a Multi-Cloud Proxy (MCP) passthrough.
  • URL Duplication Prevention: Enhanced buildProxyUrl() to prevent redundant appending of /v1/embeddings when the base URL already contains this suffix.
Changelog
  • src/app/v1/_lib/proxy/endpoint-paths.ts
    • Added /v1/embeddings to the list of known V1 endpoint paths.
    • Included /v1/embeddings in the STANDARD_ENDPOINT_PATHS array.
    • Included /v1/embeddings in the STRICT_STANDARD_ENDPOINT_PATHS array.
  • src/app/v1/_lib/proxy/format-mapper.ts
    • Updated comments to reflect support for /v1/embeddings for OpenAI and :embedContent for Gemini.
    • Modified regex patterns to detect embedContent for Gemini's v1beta and v1/publishers/google model paths.
    • Modified regex patterns to detect /v1/embeddings for OpenAI-compatible endpoints.
  • src/app/v1/_lib/proxy/forwarder.ts
    • Added /v1/embeddings to the STANDARD_ENDPOINTS array.
    • Added /v1/embeddings to the STRICT_STANDARD_ENDPOINTS array.
  • src/app/v1/_lib/url.ts
    • Added /embeddings to the targetEndpoints array for URL construction.
  • tests/unit/app/v1/url.test.ts
    • Added a new test case to verify that buildProxyUrl correctly handles base URLs already containing /embeddings without duplication.
  • tests/unit/proxy/gemini-embedcontent-format.test.ts
    • Added a new test file to validate the detectFormatByEndpoint function for Gemini's embedContent paths.
  • tests/unit/proxy/openai-embeddings-format.test.ts
    • Added a new test file to verify the format detection and endpoint classification for OpenAI's /v1/embeddings endpoint.
  • tests/unit/proxy/openai-embeddings-forwarder.test.ts
    • Added a new test file to confirm that OpenAI embeddings requests are not incorrectly routed through the MCP passthrough URL.
Activity
  • Verification steps were provided, including running specific unit tests for Gemini embed content format, OpenAI embeddings format, OpenAI embeddings forwarder, and URL utility.
  • Verification also included checking provider selector compatibility and endpoint path normalization.
  • Biome check was run on relevant source files and test files.
  • Notes indicate that all new embedding paths continue to use passthrough behavior without protocol conversion.
  • Full repo build/lint/typecheck/test was not executed; verification was targeted.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request successfully integrates support for Gemini embedContent and OpenAI-compatible /v1/embeddings endpoints. The changes are well-implemented across endpoint path definitions, format detection logic, and URL construction to prevent duplication. The addition of dedicated unit tests for both new functionalities, covering endpoint classification and proxy forwarding behavior, ensures the correctness and reliability of these features. The code is clean, follows established patterns, and directly addresses the stated objectives of the pull request.

@github-actions

Copy link
Copy Markdown
Contributor

🧪 测试结果

测试类型 状态
代码质量
单元测试
集成测试
API 测试

总体结果: ✅ 所有测试通过

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review Summary

No significant issues identified in this PR.

PR Size: M

  • Lines changed: 215
  • Files changed: 8

Review Coverage

  • Logic and correctness - Clean
  • Security (OWASP Top 10) - Clean
  • Error handling - Clean
  • Type safety - Clean
  • Documentation accuracy - Clean
  • Test coverage - Adequate
  • Code clarity - Good

Automated review by Codex AI

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  • Identified the current PR as #931 and applied the label size/M (215 lines changed across 8 files).
  • Posted a PR review comment with the summary: No significant issues identified in this PR.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review Summary

No significant issues identified in this PR. The changes implement embeddings passthrough support for Gemini and OpenAI in a clean, focused manner.

PR Size: M

  • Lines changed: 215 (208 additions, 7 deletions)
  • Files changed: 8

Changes Overview

  1. endpoint-paths.ts - Added constant and included in standard endpoint arrays
  2. format-mapper.ts - Added to OpenAI patterns and action to Gemini patterns
  3. forwarder.ts - Added to standard endpoint arrays
  4. url.ts - Added to prevent URL duplication in
  5. Test files - Added comprehensive tests for the new functionality

Review Coverage

  • Logic and correctness - Clean
  • Security (OWASP Top 10) - Clean
  • Error handling - N/A (no new error paths introduced)
  • Type safety - Clean
  • Documentation accuracy - Comments updated correctly
  • Test coverage - Adequate with 4 new test files
  • Code clarity - Good

Automated review by Claude AI

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review Summary

No significant issues identified in this PR. The changes implement embeddings passthrough support for Gemini and OpenAI in a clean, focused manner.

PR Size: M

  • Lines changed: 215 (208 additions, 7 deletions)
  • Files changed: 8

Changes Overview

  1. endpoint-paths.ts - Added EMBEDDINGS constant and included in standard endpoint arrays
  2. format-mapper.ts - Added /v1/embeddings to OpenAI patterns and embedContent action to Gemini patterns
  3. forwarder.ts - Added /v1/embeddings to standard endpoint arrays
  4. url.ts - Added /embeddings to prevent URL duplication in buildProxyUrl
  5. Test files - Added comprehensive tests for the new functionality

Review Coverage

  • Logic and correctness - Clean
  • Security (OWASP Top 10) - Clean
  • Error handling - N/A (no new error paths introduced)
  • Type safety - Clean
  • Documentation accuracy - Comments updated correctly
  • Test coverage - Adequate with 4 new test files
  • Code clarity - Good

Automated review by Claude AI

@ding113
ding113 merged commit 2df6696 into dev Mar 16, 2026
17 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in Claude Code Hub Roadmap Mar 16, 2026
@ding113
ding113 deleted the feat/embeddings-passthrough-support branch May 13, 2026 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant