Skip to content

feat: Add OpenAI Batch API Instrumentation - #2369

Merged
Luca Forstner (lforst) merged 8 commits into
mainfrom
lforst/dum-e/zurich-58ae796ad4
Aug 27, 2026
Merged

Luca Forstner (lforst) merged 8 commits into
mainfrom
lforst/dum-e/zurich-58ae796ad4

Conversation

@lforst

@lforst Luca Forstner (lforst) commented Aug 17, 2026 •

Copy link
Copy Markdown
Member

Adds resumable tracing for OpenAI Batch jobs. openaiFilesCreateTraced() starts a task span with pending LLM spans from a batch input upload; openaiBatchesRetrieveTraced() records OpenAI lifecycle timestamps; completeOpenAIBatchTrace() adds outputs and errors from caller-supplied batch files.

const inputFile = await openaiFilesCreateTraced(client.files)({
  file,
  purpose: "batch",
});

const batch = await client.batches.create({
  input_file_id: inputFile.id,
  endpoint: "/v1/chat/completions",
  completion_window: "24h",
});

Complete the trace from a poller or webhook handler. File requests start concurrently; supplied response bodies are streamed and consumed:

const batch = await openaiBatchesRetrieveTraced(client.batches)(batchId);

await completeOpenAIBatchTrace({
  inputFileId: batch.input_file_id,
  inputFileContent: client.files.content(batch.input_file_id),
  outputFileContent: batch.output_file_id
    ? client.files.content(batch.output_file_id)
    : undefined,
  errorFileContent: batch.error_file_id
    ? client.files.content(batch.error_file_id)
    : undefined,
});
openai.batch [task]
├── Chat Completion [llm]  input → output + tokens
├── Chat Completion [llm]  input → output + tokens
└── Chat Completion [llm]  input → error

@lforst

Copy link
Copy Markdown
Member Author

Abhijeet Prasad (@AbhiPrasad) refined the API a bit, see PR description.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lets do it

@lforst
Luca Forstner (lforst) merged commit bfc6556 into main Aug 27, 2026
49 checks passed
@lforst
Luca Forstner (lforst) deleted the lforst/dum-e/zurich-58ae796ad4 branch August 27, 2026 15:30
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.

2 participants