litellm - 💡(How to fix) Fix Give Feedback / Get Help: [2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
BerriAI/litellm#27188Fetched 2026-05-06 06:15:34
View on GitHub
Comments
2
Participants
2
Timeline
2
Reactions
1
Timeline (top)
commented ×2

Error Message

LiteLLM.Info: If you need to debug this error, use `litellm._turn_on_debug()'. LocalProtocolError Traceback (most recent call last) 102 except Exception as exc: The above exception was the direct cause of the following exception: LocalProtocolError Traceback (most recent call last) The above exception was the direct cause of the following exception: APIConnectionError Traceback (most recent call last) APIConnectionError: Connection error.

RAW_BUFFERClick to expand / collapse

Give Feedback / Get Help: https://github.com/BerriAI/litellm/issues/new LiteLLM.Info: If you need to debug this error, use `litellm._turn_on_debug()'.


LocalProtocolError Traceback (most recent call last) /usr/local/lib/python3.12/dist-packages/httpx/_transports/default.py in map_httpcore_exceptions() 100 try: --> 101 yield 102 except Exception as exc:

36 frames LocalProtocolError: Illegal header value b'Bearer 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\r\n'

The above exception was the direct cause of the following exception:

LocalProtocolError Traceback (most recent call last) LocalProtocolError: Illegal header value b'Bearer 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\r\n'

The above exception was the direct cause of the following exception:

APIConnectionError Traceback (most recent call last) APIConnectionError: Connection error.

extent analysis

TL;DR

Remove the newline character from the Bearer token to fix the Illegal header value error.

Guidance

  • Verify that the Bearer token does not contain any newline characters (\r\n) by checking how the token is generated and added to the request headers.
  • Check the code that sets the Authorization header to ensure it properly handles the Bearer token without adding any newline characters.
  • Use a debugger or print statements to inspect the Authorization header value before the request is sent to identify if the newline character is being added during the request preparation.
  • Consider using a library or function that properly encodes and handles headers to avoid similar issues in the future.

Notes

The error message suggests that the issue is related to the formatting of the Bearer token in the Authorization header. However, without more information about how the token is generated and added to the request, it's difficult to provide a more specific solution.

Recommendation

Apply workaround: Remove any newline characters from the Bearer token before adding it to the Authorization header. This should fix the immediate issue, but it's recommended to investigate why the newline character is being added in the first place to prevent similar issues in the future.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING