openai-php / openai-php/client

eature request: Allow overriding / per-request HTTP headers (e.g. for Langfuse, tracing, custom auth)

Open
#731 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
5.8k
Forks
679
Avg merge
19m
Merged PRs (30d)
2

Description

Many observability / tracing tools (Langfuse, Helicone, OpenLLMetry, Phoenix, etc.) in AI gateways (LiteLLM) rely on sending custom HTTP headers with every OpenAI request (e.g. langfuse-trace-id, trace-id, x-helicone-id, X-Request-ID).

Currently the only way to add custom headers is globally via withHttpHeader() on the factory — which means you have to create a completely new client instance for every request that needs different headers.
This leads to very verbose and repetitive code, especially in applications that trace many LLM calls in one flow.

Describe the solution you'd like
It would be great to have at least one of these options:

  1. Per-request header override (most useful):
$client->chat()->create([
    'model' => 'gpt-4o-mini',
    'messages' => [...],
], extraHeaders: [
    'langfuse-trace-id' => $traceId,
    'langfuse-session-id' => $sessionId,
]);

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the chat()->create entry point and trace how the factory's withHttpHeader() values reach the HTTP request. Review the existing request path and tests, then define completion as allowing per-request headers to be sent without creating a new client instance, while preserving global headers.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
api, backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.