openclaw - 💡(How to fix) Fix Bug: x-openclaw-session-key header bypasses agent routing on /v1/chat/completions [1 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
openclaw/openclaw#74679Fetched 2026-04-30 06:21:24
View on GitHub
Comments
1
Participants
2
Timeline
1
Reactions
2
Author
Timeline (top)
commented ×1

When x-openclaw-session-key is sent as an HTTP request header on the /v1/chat/completions endpoint, agent routing via the model: "openclaw/<agentId>" field is silently ignored. The request is handled by the default (main) agent regardless of the model field. Removing the header and using sessionKey in the request body instead routes correctly.

Root Cause

When x-openclaw-session-key is sent as an HTTP request header on the /v1/chat/completions endpoint, agent routing via the model: "openclaw/<agentId>" field is silently ignored. The request is handled by the default (main) agent regardless of the model field. Removing the header and using sessionKey in the request body instead routes correctly.

Fix Action

Workaround

Remove the x-openclaw-session-key header. Provide the session key only via the sessionKey field in the request body.

Code Example

curl http://<gateway>/v1/chat/completions \
  -H 'Authorization: Bearer <token>' \
  -H 'Content-Type: application/json' \
  -H 'x-openclaw-session-key: my-session-key' \
  -d '{
    "model": "openclaw/cathy",
    "sessionKey": "my-session-key",
    "messages": [{"role": "user", "content": "Who are you?"}]
  }'

---

curl http://<gateway>/v1/chat/completions \
  -H 'Authorization: Bearer <token>' \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "openclaw/cathy",
    "sessionKey": "my-session-key",
    "messages": [{"role": "user", "content": "Who are you?"}]
  }'
RAW_BUFFERClick to expand / collapse

Summary

When x-openclaw-session-key is sent as an HTTP request header on the /v1/chat/completions endpoint, agent routing via the model: "openclaw/<agentId>" field is silently ignored. The request is handled by the default (main) agent regardless of the model field. Removing the header and using sessionKey in the request body instead routes correctly.

Version

openclaw 2026.4.26

Steps to Reproduce

Fails (routes to main/default agent despite model field):

curl http://<gateway>/v1/chat/completions \
  -H 'Authorization: Bearer <token>' \
  -H 'Content-Type: application/json' \
  -H 'x-openclaw-session-key: my-session-key' \
  -d '{
    "model": "openclaw/cathy",
    "sessionKey": "my-session-key",
    "messages": [{"role": "user", "content": "Who are you?"}]
  }'

Works (routes to correct agent):

curl http://<gateway>/v1/chat/completions \
  -H 'Authorization: Bearer <token>' \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "openclaw/cathy",
    "sessionKey": "my-session-key",
    "messages": [{"role": "user", "content": "Who are you?"}]
  }'

Expected Behavior

The x-openclaw-session-key header should respect the model: "openclaw/<agentId>" routing. If the header is used to convey the session key, it should not override agent selection — the model field should still determine which agent handles the request.

Actual Behavior

Response model field correctly echoes back openclaw/cathy, but the assistant content comes from the default (main) agent. The session is created under the main agent's session store, not the target agent's.

Additional Context

  • sessionKey in the request body alone routes correctly to the target agent
  • The agentId body field is also ignored by this endpoint (only model: "openclaw/<agentId>" works for routing)
  • This was discovered while debugging external API calls (Firebase Cloud Functions) that were sending the session key as both a header and a body field
  • Session resurrection: once a session key is incorrectly assigned to the main agent, subsequent requests with that session key continue routing to main even if the header is removed — stale sessions need to be manually cleared from the main agent's sessions.json

Workaround

Remove the x-openclaw-session-key header. Provide the session key only via the sessionKey field in the request body.

extent analysis

TL;DR

Remove the x-openclaw-session-key header from the HTTP request to ensure agent routing via the model field works correctly.

Guidance

  • Verify that removing the x-openclaw-session-key header resolves the routing issue by testing with the provided curl commands.
  • Ensure the sessionKey is only provided in the request body to maintain correct agent routing.
  • Be aware that stale sessions may need to be manually cleared from the main agent's sessions.json if the session key was previously incorrectly assigned.
  • Consider updating external API calls (e.g., Firebase Cloud Functions) to remove the x-openclaw-session-key header and only use the sessionKey field in the request body.

Example

No code snippet is necessary as the issue is resolved by modifying the request headers and body as shown in the provided curl commands.

Notes

The root cause of the issue appears to be a conflict between the x-openclaw-session-key header and the model field in the request body. Removing the header resolves the issue, but it may be beneficial to investigate why this conflict occurs in the first place.

Recommendation

Apply the workaround by removing the x-openclaw-session-key header, as it is a straightforward and effective solution to the routing issue.

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

openclaw - 💡(How to fix) Fix Bug: x-openclaw-session-key header bypasses agent routing on /v1/chat/completions [1 comments, 2 participants]