APIHandler possible error with per_req_config_modifier #156

Closed
opened 2026-02-16 00:19:02 -05:00 by yindo · 3 comments
Owner

Originally created by @GilbertGomez94 on GitHub (Apr 3, 2024).

APIHandler code:

async def _get_api_handler() -> APIHandler:
    """Prepare a RunnableLambda."""
    return APIHandler(RunnableLambda(answer_ext),
                      path="/v2",
                      per_req_config_modifier=fetch_config_headers)

fetch_config_headers code:

    if "x-api-user" in req.headers:
        config["configurable"]["user"] = req.headers["x-api-user"]
    else:
        raise HTTPException(401, "No API user provided")

    return config

When I call the endpoint, the following error appears:

config["configurable"]["user"] = req.headers["x-api-user"]
KeyError: 'configurable'

This is the body of the request:

{
    "input":{
        "chat_history":[],
        "question":"some question"
    },
    "config":{
        "configurable":{
            "llm": "openai"
        }
    }
}

I'm using langserve 0.0.51

I hope someone can help me, thanks!

Originally created by @GilbertGomez94 on GitHub (Apr 3, 2024). APIHandler code: ``` async def _get_api_handler() -> APIHandler: """Prepare a RunnableLambda.""" return APIHandler(RunnableLambda(answer_ext), path="/v2", per_req_config_modifier=fetch_config_headers) ``` fetch_config_headers code: ```def fetch_config_headers(config: Dict[str, Any], req: Request) -> Dict[str, Any]: if "x-api-user" in req.headers: config["configurable"]["user"] = req.headers["x-api-user"] else: raise HTTPException(401, "No API user provided") return config ``` When I call the endpoint, the following error appears: ``` config["configurable"]["user"] = req.headers["x-api-user"] KeyError: 'configurable' ``` This is the body of the request: ``` { "input":{ "chat_history":[], "question":"some question" }, "config":{ "configurable":{ "llm": "openai" } } } ``` I'm using langserve 0.0.51 I hope someone can help me, thanks!
yindo closed this issue 2026-02-16 00:19:02 -05:00
Author
Owner

@eyurtsev commented on GitHub (Apr 3, 2024):

Could you include a minimal reproducible example?

@eyurtsev commented on GitHub (Apr 3, 2024): Could you include a minimal reproducible example?
Author
Owner

@eyurtsev commented on GitHub (Apr 3, 2024):

Can do this:

if 'configurable' in config:
    config["configurable"]["user"] = req.headers["x-api-user"]
else:
    
    configurable  = {'user': req.headers["x-api-user"]}
    config['configurable'] = configurable
@eyurtsev commented on GitHub (Apr 3, 2024): Can do this: ```python if 'configurable' in config: config["configurable"]["user"] = req.headers["x-api-user"] else: configurable = {'user': req.headers["x-api-user"]} config['configurable'] = configurable ```
Author
Owner

@eyurtsev commented on GitHub (Apr 12, 2024):

Assuming issue is resolved. Feel free to open another issue if this is still unsolved.

@eyurtsev commented on GitHub (Apr 12, 2024): Assuming issue is resolved. Feel free to open another issue if this is still unsolved.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langserve#156