From 5cd22739b4256b6fe8f9a89ef20e71df362080e5 Mon Sep 17 00:00:00 2001 From: Tyagiquamar Date: Sun, 13 Sep 2026 14:38:50 +0530 Subject: [PATCH] fix(js): support /v1/embeddings endpoint in OpenAI batch instrumentation (#2425) --- .../openai-batch-instrumentation.test.ts | 29 +++++++++++++++++++ .../plugins/openai-batch-instrumentation.ts | 6 +++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/js/src/instrumentation/plugins/openai-batch-instrumentation.test.ts b/js/src/instrumentation/plugins/openai-batch-instrumentation.test.ts index 96a2809ef..b09093c95 100644 --- a/js/src/instrumentation/plugins/openai-batch-instrumentation.test.ts +++ b/js/src/instrumentation/plugins/openai-batch-instrumentation.test.ts @@ -394,4 +394,33 @@ describe("OpenAI Batch instrumentation", () => { expect(received).toBe(content); expect(await backgroundLogger.drain()).toEqual([]); }); + + it("supports /v1/embeddings batch requests", async () => { + const embeddingsInput = [ + { + custom_id: "emb1", + method: "POST", + url: "/v1/embeddings", + body: { + model: "text-embedding-3-small", + input: "hello world", + }, + }, + ]; + + let received = ""; + const result = await openaiFilesCreateTraced({ + create(params: { file: Blob; purpose: string }) { + return asyncAPIPromise( + Promise.resolve({ id: "file_emb" }).then(async (file) => { + received = await params.file.text(); + return file; + }), + ); + }, + })({ file: new Blob([jsonl(embeddingsInput)]), purpose: "batch" }); + + expect(result).toEqual({ id: "file_emb" }); + expect(received).toBe(jsonl(embeddingsInput)); + }); }); diff --git a/js/src/instrumentation/plugins/openai-batch-instrumentation.ts b/js/src/instrumentation/plugins/openai-batch-instrumentation.ts index 560ac51ca..cb2e2aa31 100644 --- a/js/src/instrumentation/plugins/openai-batch-instrumentation.ts +++ b/js/src/instrumentation/plugins/openai-batch-instrumentation.ts @@ -26,7 +26,11 @@ import { processImagesInOutput, } from "./openai-span-data"; -const SUPPORTED_ENDPOINTS = new Set(["/v1/chat/completions", "/v1/responses"]); +const SUPPORTED_ENDPOINTS = new Set([ + "/v1/chat/completions", + "/v1/responses", + "/v1/embeddings", +]); const TERMINAL_STATUSES = new Set([ "completed", "failed",