openai-php / openai-php/client
eature request: Allow overriding / per-request HTTP headers (e.g. for Langfuse, tracing, custom auth)
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:
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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