Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions supabase/functions/generate-embeddings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,19 @@ serve(async (req) => {
const summaryText = JSON.stringify(meeting.meeting_summary_json);

// Generate embedding using Gemini
const embeddingResponse = await fetch("https://generativelanguage.googleapis.com/v1/models/embedding-001:embedContent?key=" + GEMINI_API_KEY, {
const embeddingResponse = await fetch("https://generativelanguage.googleapis.com/v1beta/models/gemini-embedding-001:embedContent?key=" + GEMINI_API_KEY, {
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

GEMINI_API_KEY is interpolated without a guard β€” requests silently go out with key=undefined.

If the env var is missing, GEMINI_API_KEY is undefined and string concatenation produces the literal query string ?key=undefined. The request reaches Google, fails with an opaque auth error, and the real cause (missing secret) is hidden. Fail fast before the fetch.

Proposed fix
+    if (!GEMINI_API_KEY) {
+      throw new Error("GEMINI_API_KEY is not configured");
+    }
+
     const embeddingResponse = await fetch(
-      "https://generativelanguage.googleapis.com/v1beta/models/gemini-embedding-001:embedContent?key=" + GEMINI_API_KEY,
+      `https://generativelanguage.googleapis.com/v1beta/models/gemini-embedding-001:embedContent?key=${GEMINI_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
const embeddingResponse = await fetch("https://generativelanguage.googleapis.com/v1beta/models/gemini-embedding-001:embedContent?key=" + GEMINI_API_KEY, {
if (!GEMINI_API_KEY) {
throw new Error("GEMINI_API_KEY is not configured");
}
const embeddingResponse = await fetch(
`https://generativelanguage.googleapis.com/v1beta/models/gemini-embedding-001:embedContent?key=${GEMINI_API_KEY}`,
{
πŸ€– Prompt for AI Agents
In `@supabase/functions/generate-embeddings/index.ts` at line 52, The code
performs the fetch using GEMINI_API_KEY directly (see the fetch call that builds
the URL with "?key=" + GEMINI_API_KEY); add a pre-flight check that verifies
GEMINI_API_KEY is defined and non-empty (e.g., at the start of the function
handling embeddings or before the fetch), and if missing throw or return an
explicit error/HTTP 500 with a clear message like "Missing GEMINI_API_KEY" so
the request never proceeds with key=undefined; update any surrounding error
handling in the embedding generation function to surface this failure
immediately.

method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "embedding-001",
content: {
parts: [
{
text: summaryText
}
]
},
taskType: "RETRIEVAL_DOCUMENT"
}
}),
});

Expand Down
8 changes: 3 additions & 5 deletions supabase/functions/get-embedding/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,20 @@ serve(async (req) => {
throw new Error("No text provided for embedding");
}

// Generate embedding using Gemini
const embeddingResponse = await fetch("https://generativelanguage.googleapis.com/v1/models/embedding-001:embedContent?key=" + GEMINI_API_KEY, {
// Generate embedding using Gemini embedding model
const embeddingResponse = await fetch("https://generativelanguage.googleapis.com/v1beta/models/gemini-embedding-001:embedContent?key=" + GEMINI_API_KEY, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "embedding-001",
content: {
parts: [
{
text: text
}
]
},
taskType: "RETRIEVAL_QUERY"
}
}),
});

Expand Down