Skip to content

fix(inference): pass extra_headers as HTTP headers instead of in request body#1216

Merged
toubatbrian merged 1 commit intolivekit:mainfrom
smorimoto:fix/extra-headers-in-request-body
Apr 9, 2026
Merged

fix(inference): pass extra_headers as HTTP headers instead of in request body#1216
toubatbrian merged 1 commit intolivekit:mainfrom
smorimoto:fix/extra-headers-in-request-body

Conversation

@smorimoto
Copy link
Copy Markdown
Contributor

@smorimoto smorimoto commented Apr 9, 2026

Problem

PR #1208 introduced metadata headers for inference requests. In agents/src/inference/llm.ts, extra_headers is set on the requestOptions object, which is then spread into the first argument (request body) of client.chat.completions.create(). The OpenAI API rejects this with a 400 error:

APIStatusError: 400 Unrecognized request argument supplied: extra_headers

This affects all inference LLM calls made through the @livekit/agents package (v1.2.4).

Solution

  • Remove extra_headers from requestOptions before it is spread into the request body (delete requestOptions.extra_headers)
  • Pass the headers via the second argument (RequestOptions.headers) of create(), where the OpenAI SDK expects them

The other inference transports (STT, TTS, interruption HTTP/WS) already handle headers correctly — this bug is isolated to the LLM inference path.

Verification

  1. Build succeeds: pnpm build:agents
  2. Lint and formatting pass: pnpm lint, pnpm format:check
  3. No public API surface changes: pnpm api:check
  4. Run an agent that uses the inference LLM layer against the OpenAI API and confirm the 400 error no longer occurs

…est body

extra_headers was being spread into the OpenAI SDK's create() body
parameter, causing the API to reject the request with 400
"Unrecognised request argument supplied: extra_headers". Move it to
the second parameter (RequestOptions.headers) where it belongs.
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 9, 2026

🦋 Changeset detected

Latest commit: fe7974d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 22 packages
Name Type
@livekit/agents Patch
@livekit/agents-plugin-anam Patch
@livekit/agents-plugin-baseten Patch
@livekit/agents-plugin-bey Patch
@livekit/agents-plugin-cartesia Patch
@livekit/agents-plugin-deepgram Patch
@livekit/agents-plugin-elevenlabs Patch
@livekit/agents-plugin-google Patch
@livekit/agents-plugin-hedra Patch
@livekit/agents-plugin-inworld Patch
@livekit/agents-plugin-lemonslice Patch
@livekit/agents-plugin-livekit Patch
@livekit/agents-plugin-neuphonic Patch
@livekit/agents-plugin-openai Patch
@livekit/agents-plugin-phonic Patch
@livekit/agents-plugin-resemble Patch
@livekit/agents-plugin-rime Patch
@livekit/agents-plugin-sarvam Patch
@livekit/agents-plugin-silero Patch
@livekit/agents-plugins-test Patch
@livekit/agents-plugin-trugen Patch
@livekit/agents-plugin-xai Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@smorimoto
Copy link
Copy Markdown
Contributor Author

@codex review

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@toubatbrian toubatbrian merged commit 8a06cac into livekit:main Apr 9, 2026
5 checks passed
@github-actions github-actions Bot mentioned this pull request Apr 9, 2026
@smorimoto smorimoto deleted the fix/extra-headers-in-request-body branch April 10, 2026 02:12
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