LangGraph API server merges HTTP headers into runtime context causing TypeErrors in context schemas #912

Closed
opened 2026-02-20 17:42:20 -05:00 by yindo · 7 comments
Owner

Originally created by @jfernandez on GitHub (Aug 11, 2025).

Checked other resources

  • This is a bug, not a usage question. For questions, please use the LangChain Forum (https://forum.langchain.com/).
  • I added a clear and detailed title that summarizes the issue.
  • I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example).
  • I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue.

Example Code

# Define a simple context dataclass
from dataclasses import dataclass
from typing import Literal

@dataclass
class MyContext:
    user_id: str | None = None
    access_token: str | None = None
    timezone: str | None = None
    provider: Literal["anthropic", "openai", "fireworks", "google"] | None = None
    model: str | None = None

# langgraph.json configuration
{
    "auth": {
        "type": "function",
        "function": "src.config.auth:auth"
    },
    "graphs": {
        "agent": "./src/agent/graph.py:graph"
    }
}

# Authentication function that returns context
def auth(request):
    # Extract user info and return context
    return {
        "user_id": "123",
        "timezone": "America/New_York"
    }

# When making HTTP request to LangGraph API server:
# POST /threads/abc/runs
# Headers:
#   Host: localhost:8123
#   User-Agent: python-requests/2.31.0
#   Accept: application/json
#   Authorization: Bearer token123

# The LangGraph API server merges HTTP headers into the context,
# causing this error when initializing MyContext:
# TypeError: MyContext.__init__() got an unexpected keyword argument 'host'

Error Message and Stack Trace (if applicable)

TypeError: MyContext.__init__() got an unexpected keyword argument 'host'
TypeError: MyContext.__init__() got an unexpected keyword argument 'user-agent'
TypeError: MyContext.__init__() got an unexpected keyword argument 'accept-encoding'
TypeError: MyContext.__init__() got an unexpected keyword argument 'accept-language'
TypeError: MyContext.__init__() got an unexpected keyword argument 'authorization'

Description

When using the LangGraph API server with LangGraph 0.6 Runtime Context API, the server incorrectly merges HTTP headers from the incoming request into the runtime context object. This causes TypeError exceptions when the context dataclass doesn't expect these additional fields.

Expected Behavior

The LangGraph API server should only pass the context fields returned by the authentication function to the runtime context, not HTTP headers from the request.

Actual Behavior

HTTP headers like host, user-agent, accept-encoding, etc. are being merged into the context object, causing TypeErrors when initializing context dataclasses that don't have fields for these headers.

Impact

This prevents users from defining strict context schemas and breaks applications that use standard dataclasses for runtime context without custom __init__ methods to handle unexpected fields.

Workaround

Currently requires implementing a custom __init__ method in the context dataclass to accept and ignore unexpected keyword arguments.

System Info

Environment:

  • LangGraph: 0.6.x
    • LangGraph API: 0.2.x
      • Python: 3.11+
        • Operating System: macOS/Linux
          LangGraph Configuration:
{
  "auth": {
    "type": "function",
    "function": "src.config.auth:auth"
  },
  "graphs": {
    "agent": "./src/agent/graph.py:graph"
  }
}

Runtime Context API Usage:
Using LangGraph 0.6 Runtime[Context] pattern with custom dataclass context schemas.

Originally created by @jfernandez on GitHub (Aug 11, 2025). ### Checked other resources - [x] This is a bug, not a usage question. For questions, please use the LangChain Forum (https://forum.langchain.com/). - [x] I added a clear and detailed title that summarizes the issue. - [x] I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example). - [x] I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue. ### Example Code ```python # Define a simple context dataclass from dataclasses import dataclass from typing import Literal @dataclass class MyContext: user_id: str | None = None access_token: str | None = None timezone: str | None = None provider: Literal["anthropic", "openai", "fireworks", "google"] | None = None model: str | None = None # langgraph.json configuration { "auth": { "type": "function", "function": "src.config.auth:auth" }, "graphs": { "agent": "./src/agent/graph.py:graph" } } # Authentication function that returns context def auth(request): # Extract user info and return context return { "user_id": "123", "timezone": "America/New_York" } # When making HTTP request to LangGraph API server: # POST /threads/abc/runs # Headers: # Host: localhost:8123 # User-Agent: python-requests/2.31.0 # Accept: application/json # Authorization: Bearer token123 # The LangGraph API server merges HTTP headers into the context, # causing this error when initializing MyContext: # TypeError: MyContext.__init__() got an unexpected keyword argument 'host' ``` ### Error Message and Stack Trace (if applicable) ```shell TypeError: MyContext.__init__() got an unexpected keyword argument 'host' TypeError: MyContext.__init__() got an unexpected keyword argument 'user-agent' TypeError: MyContext.__init__() got an unexpected keyword argument 'accept-encoding' TypeError: MyContext.__init__() got an unexpected keyword argument 'accept-language' TypeError: MyContext.__init__() got an unexpected keyword argument 'authorization' ``` ### Description When using the LangGraph API server with LangGraph 0.6 Runtime Context API, the server incorrectly merges HTTP headers from the incoming request into the runtime context object. This causes `TypeError` exceptions when the context dataclass doesn't expect these additional fields. ## Expected Behavior The LangGraph API server should only pass the context fields returned by the authentication function to the runtime context, not HTTP headers from the request. ## Actual Behavior HTTP headers like `host`, `user-agent`, `accept-encoding`, etc. are being merged into the context object, causing TypeErrors when initializing context dataclasses that don't have fields for these headers. ## Impact This prevents users from defining strict context schemas and breaks applications that use standard dataclasses for runtime context without custom `__init__` methods to handle unexpected fields. ## Workaround Currently requires implementing a custom `__init__` method in the context dataclass to accept and ignore unexpected keyword arguments. ### System Info **Environment:** - LangGraph: 0.6.x - - LangGraph API: 0.2.x - - - Python: 3.11+ - - - - Operating System: macOS/Linux **LangGraph Configuration:** ```json { "auth": { "type": "function", "function": "src.config.auth:auth" }, "graphs": { "agent": "./src/agent/graph.py:graph" } } ``` **Runtime Context API Usage:** Using LangGraph 0.6 `Runtime[Context]` pattern with custom dataclass context schemas.
yindo added the bugpending labels 2026-02-20 17:42:20 -05:00
yindo closed this issue 2026-02-20 17:42:20 -05:00
Author
Owner

@AnhQuanTrl commented on GitHub (Aug 11, 2025):

https://github.com/langchain-ai/langgraph/pull/5736/files
This seems like the PR that results in this change. Our Deployments in LangGraph Platform get broken because of this. 😔

@AnhQuanTrl commented on GitHub (Aug 11, 2025): https://github.com/langchain-ai/langgraph/pull/5736/files This seems like the PR that results in this change. Our Deployments in LangGraph Platform get broken because of this. 😔
Author
Owner

@atharv-honestly commented on GitHub (Aug 11, 2025):

Yep, our production is down, any quick fix?

@atharv-honestly commented on GitHub (Aug 11, 2025): Yep, our production is down, any quick fix?
Author
Owner

@anatolii-levchenko-sweb commented on GitHub (Aug 11, 2025):

+1 production is down

@anatolii-levchenko-sweb commented on GitHub (Aug 11, 2025): +1 production is down
Author
Owner

@AnhQuanTrl commented on GitHub (Aug 11, 2025):

Yep, our production is down, any quick fix?

What I did is to convert dataclass to pydantic BaseModel and then add this:

model_config = ConfigDict(extra="ignore")
@AnhQuanTrl commented on GitHub (Aug 11, 2025): > Yep, our production is down, any quick fix? What I did is to convert dataclass to pydantic BaseModel and then add this: ``` model_config = ConfigDict(extra="ignore") ```
Author
Owner

@maksimay commented on GitHub (Aug 11, 2025):

production down here ++ please fix

@maksimay commented on GitHub (Aug 11, 2025): production down here ++ please fix
Author
Owner

@coralreefman commented on GitHub (Aug 11, 2025):

same here, is there any way to deploy without always using the latest langgraph-api?

@coralreefman commented on GitHub (Aug 11, 2025): same here, is there any way to deploy without always using the latest langgraph-api?
Author
Owner

@jdrogers940 commented on GitHub (Aug 11, 2025):

Hey folks, thanks for the report and apologies for the pain here. There's a new version of langgraph-api available (v0.2.129) that should fix this issue.

@jdrogers940 commented on GitHub (Aug 11, 2025): Hey folks, thanks for the report and apologies for the pain here. There's a new version of langgraph-api available (v0.2.129) that should fix this issue.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#912