Skip to content
LUNAROUTEDocs

Build your own harness

You are writing something that talks to LunaRoute: a new agent CLI, a fork of one we don’t ship, a bot of your own. This page assumes you already have an API key and speak one of our dialects — OpenAI Chat Completions, Anthropic Messages, or the Responses API. What’s left is a small set of headers that make your traffic behave well and be attributable.

Header Value
X-LunaRoute-Session One stable id per conversation. Keep it across turns; mint a new one per conversation.
LunaRoute-Session-Id The same value, sent again, so requests are attributed to this session.
LunaRoute-Agent Your harness as name/version, lowercase, e.g. myharness/1.2.3.
Terminal window
curl https://gw.lunaroute.com/v1/chat/completions \
-H "Authorization: Bearer $LUNAROUTE_API_KEY" \
-H "Content-Type: application/json" \
-H "X-LunaRoute-Session: 6f2a1c93-conv-01" \
-H "LunaRoute-Session-Id: 6f2a1c93-conv-01" \
-H "LunaRoute-Agent: myharness/1.2.3" \
-d '{"model":"glm-5.3","messages":[{"role":"user","content":"hello"}]}'

None of these headers can make a request fail.

Header Value
Thread-Id A task inside a conversation, if your harness has that notion. Optional.
LunaRoute-Request-Id Your own id for one request, so you can line our records up with your logs. Optional.

x-session-id, x-conversation-id and conversation-id already keep a conversation on one server, but they do not attribute usage to a session. session-id does both. Header names are case-insensitive, so a client already sending Session-Id is already covered — keep sending it.

X-LunaRoute-Session decides routing and LunaRoute-Session-Id decides attribution, and we know that is awkward. Send both with the same value.

  • We keep a conversation on the same LunaRoute inference server for 30 minutes after its last successful request, refreshed on each success. The point is a warm cache: a faster first token.
  • It is a preference, not a guarantee. Your conversation moves when that server is unhealthy, saturated, queueing, or no longer part of the model’s pool.
  • The pin is remembered per gateway instance, and we run many. Under load two turns of one conversation can reach different instances, each pinning its own server. The header makes same-box likely, not certain.
  • It applies when we choose the server — requests to LunaRoute-hosted models. A request routed out to a provider with your own key never pins, because there is no server of ours to pin to.
  • Without any session header we derive a key from the conversation’s opening — the first 2 KiB after any system prompt. Long conversations keep the same key as they grow; a shorter one re-keys on every turn. That is the main reason to send the header.

X-LunaRoute-Client picks a model catalog shape for a specific client, and X-LunaRoute-Scheduler asks for a concurrency tier; both are documented elsewhere (Models API, Concurrency & overflow). Every other X-LunaRoute-* header is reserved for LunaRoute’s own components — don’t send them, and don’t rely on them having any effect.

  • Headers used for pinning: any readable ASCII value, no length limit. An unusable value is ignored and routing falls back to the conversation itself.
  • Headers used for attribution (LunaRoute-Session-Id, Thread-Id, LunaRoute-Request-Id, LunaRoute-Agent): 128 characters, printable ASCII or spaces. Anything longer or non-ASCII is dropped silently rather than rejected.
  • Never put a secret in any of these. They are stored in our usage records.