Skip to content

fix(fireworks_ai): restore Content-Type application/json header (fixes 415) - #33929

Merged
krrish-berri-2 merged 3 commits into
litellm_internal_stagingfrom
litellm_fix_fireworks_content_type
Jul 20, 2026
Merged

krrish-berri-2 merged 3 commits into
litellm_internal_stagingfrom
litellm_fix_fireworks_content_type

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Jul 19, 2026 •

Copy link
Copy Markdown
Contributor

Relevant issues

Regression from #33717 (commit b3d05bd, "feat(fireworks_ai): map litellm session id to x-session-affinity header for prompt caching"). Fireworks chat requests started failing with 415 Unsupported Media Type

Linear ticket

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • My PR passes all CI/CD checks (e.g., lint, format, unit tests)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to re-request a review after pushing changes)

Screenshots / Proof of Fix

Live Fireworks calls through litellm.completion (real API, no mocks)

Before the fix, at commit 82c3313083 with the new Content-Type line removed to recreate the pre-#33717 header behavior:

$ LITELLM_LOCAL_MODEL_COST_MAP=True uv run --no-sync python /tmp/fw_proof.py
litellm.llms.custom_httpx.http_handler.MaskedHTTPStatusError: Client error '415 Unsupported Media Type'
for url 'https://api.fireworks.ai/inference/v1/chat/completions'

After the fix, at commit 82c3313083:

$ LITELLM_LOCAL_MODEL_COST_MAP=True uv run --no-sync python /tmp/fw_proof.py
STATUS: OK

$ LITELLM_LOCAL_MODEL_COST_MAP=True uv run --no-sync python /tmp/fw_proof2.py
HTTP path OK, content: 'The user wants me to reply with the single word'

The scripts call model="fireworks_ai/accounts/fireworks/models/gpt-oss-120b" (and kimi-k2p6) with a short user message

Type

🐛 Bug Fix
🧹 Refactoring

Changes

#33717 changed FireworksAIConfig from class FireworksAIConfig(OpenAIGPTConfig) to class FireworksAIConfig(FireworksAIMixin, OpenAIGPTConfig). Putting the mixin first in the MRO was deliberate; that is how chat requests pick up the new x-session-affinity header, which lives in FireworksAIMixin.validate_environment. If the mixin were placed after OpenAIGPTConfig, the parent validate_environment would win and the session-affinity header would never be set. The problem is that the two implementations were not equivalent: the parent sets a default Content-Type: application/json, the mixin did not. Flipping precedence to the mixin silently dropped that default, and since the body is posted as a pre-serialized string via data=json.dumps(data), httpx never re-adds it, so Fireworks rejects the body as application/octet-stream and returns 415

Rather than duplicating the Content-Type default inside the mixin (which would leave two copies free to drift apart again), FireworksAIConfig now owns its validate_environment: it resolves the Fireworks API key, delegates header construction to OpenAIGPTConfig.validate_environment, then layers only the Fireworks-specific x-session-affinity header on top. The Content-Type default now comes from the OpenAI base and can no longer drift

class FireworksAIConfig(FireworksAIMixin, OpenAIGPTConfig):
    def validate_environment(self, headers, model, messages, optional_params, litellm_params, api_key=None, api_base=None) -> dict:
        api_key = self._get_api_key(api_key)
        if api_key is None:
            raise ValueError("FIREWORKS_API_KEY is not set")
        validated_headers = OpenAIGPTConfig.validate_environment(self, headers=headers, ..., api_key=api_key, api_base=api_base)
        return self._add_session_affinity_header(validated_headers, litellm_params)

The mixin keeps a self-contained validate_environment (Authorization + Content-Type default + session affinity) for the text-completion config, whose base does not provide a working validate_environment; the session-affinity logic is shared through the new _add_session_affinity_header helper. The rerank config was already overriding validate_environment with its own JSON headers, so it is unaffected

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

Link to Devin session: https://app.devin.ai/sessions/fbf309f4b50246be91aac926083df16b
Requested by: @krrish-berri-2

…ronment

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@krrish-berri-2 krrish-berri-2 self-assigned this Jul 19, 2026
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@greptile-apps

greptile-apps Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR restores the Content-Type: application/json header that was dropped when #33717 introduced FireworksAIMixin and its validate_environment shadowed OpenAIGPTConfig.validate_environment, which had previously set this header. Without it, httpx sends the pre-serialised JSON string with no content type and Fireworks rejects the request with 415.

  • common_utils.py: Two lines added to FireworksAIMixin.validate_environment — a case-insensitive scan of the outgoing header dict, and a Content-Type: application/json default only when the caller has not already supplied one. This pattern mirrors how the session-affinity header is handled immediately below.
  • Test file: Two new unit tests cover the happy path (header injected when absent) and the preservation path (caller-supplied content-type is not overwritten), with no network calls.

Confidence Score: 5/5

The change is a minimal two-line addition isolated to the Fireworks provider with no effect on any other path.

The case-insensitive content-type check is correct, the fix applies correctly to all three FireworksAIMixin subclasses, and the two new tests cover both injection and preservation paths without weakening existing coverage.

No files require special attention.

Important Files Changed

Filename Overview
litellm/llms/fireworks_ai/common_utils.py Adds Content-Type: application/json default to FireworksAIMixin.validate_environment when the caller has not already set one; correctly uses a case-insensitive key scan so explicit overrides are preserved.
tests/test_litellm/llms/fireworks_ai/chat/test_fireworks_ai_chat_transformation.py Adds two new mock-only unit tests: one verifying the default Content-Type: application/json header is injected, and one verifying a caller-supplied content-type is not overwritten; no network calls are made.

Reviews (1): Last reviewed commit: "fix(fireworks_ai): set Content-Type appl..." | Re-trigger Greptile

@codecov

codecov Bot commented Jul 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.25000% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
litellm/llms/fireworks_ai/common_utils.py 70.00% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

@codspeed

codspeed Bot commented Jul 19, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_fix_fireworks_content_type (66c2533) with litellm_internal_staging (067c9bb)

Open in CodSpeed

@Thijmen

Thijmen commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Confirmed that this works ✅ can we get this in in a RC?

krrish-berri and others added 2 commits July 20, 2026 16:04
…PTConfig

Instead of re-adding the JSON Content-Type default inside FireworksAIMixin,
FireworksAIConfig now delegates header construction to OpenAIGPTConfig and only
layers the Fireworks-specific x-session-affinity header on top, so the
Content-Type default can no longer drift away from the OpenAI base and reintroduce
the 415.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…_environment

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@krrish-berri-2
krrish-berri-2 merged commit 3fcd19d into litellm_internal_staging Jul 20, 2026
76 checks passed
@krrish-berri-2
krrish-berri-2 deleted the litellm_fix_fireworks_content_type branch July 20, 2026 16:52
@krrish-berri-2

Copy link
Copy Markdown
Contributor

yes @Thijmen

cc: @yuneng-berri

yuneng-berri added a commit that referenced this pull request Jul 20, 2026
…eworks_ct

chore(release): backport #33929 to rc/1.94.0
ap-anton-r-susilo pushed a commit to ap-anton-r-susilo/litellm that referenced this pull request Jul 29, 2026
…s 415) (BerriAI#33929)

* fix(fireworks_ai): set Content-Type application/json in validate_environment

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* refactor(fireworks_ai): delegate chat validate_environment to OpenAIGPTConfig

Instead of re-adding the JSON Content-Type default inside FireworksAIMixin,
FireworksAIConfig now delegates header construction to OpenAIGPTConfig and only
layers the Fireworks-specific x-session-affinity header on top, so the
Content-Type default can no longer drift away from the OpenAI base and reintroduce
the 415.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* test(fireworks_ai): cover missing api key error path in chat validate_environment

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

---------

Co-authored-by: Krrish Dholakia <krrishdholakia@berri.ai>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
(cherry picked from commit 3fcd19d)
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.

4 participants