Skip to content

feat: Add OpenAI Batch API Instrumentation - #2369

Open
Luca Forstner (lforst) wants to merge 7 commits into
mainfrom
lforst/dum-e/zurich-58ae796ad4
Open

feat: Add OpenAI Batch API Instrumentation#2369
Luca Forstner (lforst) wants to merge 7 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 without making OpenAI API calls. startOpenAIBatchTrace() starts a task span with pending LLM spans and returns instrumented create parameters; completeOpenAIBatchTrace() finishes those spans from caller-supplied batch files.

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

const params = await startOpenAIBatchTrace({
  inputFile,
  input: jsonl, // JSONL string or parsed records
  params: {
    endpoint: "/v1/chat/completions",
    completion_window: "24h",
  },
});

// Only user code calls OpenAI.
const batch = await client.batches.create(params);

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

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

await completeOpenAIBatchTrace({
  batch,
  inputFile: client.files.content(batch.input_file_id),
  outputFile: batch.output_file_id
    ? client.files.content(batch.output_file_id)
    : undefined,
  errorFile: 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

Luca Forstner (lforst) and others added 7 commits August 17, 2026 12:59
Automated regeneration of SDK types.

---------

Co-authored-by: braintrust-bot[bot] <215900051+braintrust-bot[bot]@users.noreply.github.com>
Co-authored-by: lforst <8118419+lforst@users.noreply.github.com>
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.

1 participant