Connect a gateway
If your apps call models through an LLM gateway, Morse can read the calls that gateway already routes. Your gateway sends a copy of each call to Morse over OpenTelemetry. Morse prices it, assigns it to an agent and counts it in your spend. That includes spend from apps you have not instrumented with the Morse SDK.
Morse reads your gateway. It never sits in your request path, and it never changes your gateway’s settings.
Turn on gateway ingest
Gateway ingest is off until someone turns it on for your organization. Org owners and admins can do this themselves.
- Go to Settings → Integrations → Gateways and select Turn on gateway ingest.
- Read what changes and confirm. Once it is on, traffic from your gateway is read as gateway calls instead of ordinary traces.
- Then connect a gateway.
Turning it on does not store prompts or completions. That stays off unless you turn on Capture prompts for a gateway.
To turn it off, select Turn off in the same place. New gateway traffic is then stored as ordinary traces again. Gateway data you already have stays.
If your plan includes gateway ingest, the Gateways section says so. It is on for you and cannot be turned off there.
Demo workspaces cannot change this setting.
Where it lives
Open Settings → Integrations. Every organization has a Gateways section. While gateway ingest is off, it shows Turn on gateway ingest. Once it is on, it lists every connected gateway, with budget drift, unattributed spend and attribution rules below it. Start with Connect a gateway.
The Connect a gateway wizard has three steps:
- Pick your gateway: LiteLLM, Vercel AI Gateway, OpenRouter, or Other OpenTelemetry gateway. Cloudflare AI Gateway is listed as Not available yet.
- Pick an environment key. Calls from this gateway land in that environment, so dev keys stay out of production views.
- Copy the setup. The snippet is filled in for the kind you picked. Replace
<your environment key>with an environment key that has write scope. You can create one in Settings → API keys.
After you copy the setup, send one request through your gateway. The wizard shows Waiting for first event and checks every few seconds. It switches to Receiving when the first event lands. After 10 minutes with no event it shows a troubleshooting checklist.
Every setup uses Authorization: Bearer with your environment key. X-API-Key is not accepted.
Every setup also sends an X-Morse-Gateway-Kind header. It keeps your gateway’s calls out of the
span limits your agents’ traces use. See Rate limits.
The endpoint is the Morse OTLP traces endpoint, https://api.morseai.dev/api/v1/otlp/v1/traces.
LiteLLM
Add this to the LiteLLM proxy’s config.yaml and its environment:
# config.yaml
litellm_settings:
callbacks: ["otel"]
turn_off_message_logging: true
# environment of the LiteLLM proxy
OTEL_EXPORTER="otlp_http"
OTEL_ENDPOINT="https://api.morseai.dev/api/v1/otlp/v1/traces"
OTEL_HEADERS="Authorization=Bearer <your environment key>,X-Morse-Gateway-Kind=litellm"
USE_OTEL_LITELLM_REQUEST_SPAN="true"- Verified with LiteLLM 1.108.9. Older proxies (1.79 tested) export spans without the call id Morse needs, so their calls are not recorded.
USE_OTEL_LITELLM_REQUEST_SPAN=trueis required. Without it LiteLLM exports only its internal request spans, with no model, cost or key.turn_off_message_logging: truekeeps prompts and completions out of the export.- Restart the proxy after you change its environment.
- To tag an agent, set
metadata.morse_agentto the agent’s name on the request.
Vercel AI Gateway
Vercel sends AI Gateway calls to Morse through a drain. In the Vercel dashboard, open Team Settings → Drains → Add Drain → AI Gateway and fill it in like this:
# Vercel dashboard > Team Settings > Drains > Add Drain > AI Gateway
Projects: All Projects (includes API keys not linked to a project)
Destination: Custom Endpoint
URL: https://api.morseai.dev/api/v1/otlp/v1/traces
Encoding: Protobuf
Custom Headers: on, two lines:
Authorization: Bearer <your environment key>
X-Morse-Gateway-Kind: vercel- Pick the AI Gateway data type, not Traces. A Traces drain does not carry AI Gateway calls made with an API key.
- Drains need a paid Vercel Pro or Enterprise plan (not a Pro trial), and Vercel bills drains per trace.
- Keep the
X-Morse-Gateway-Kindheader. Morse recognizes the Vercel AI Gateway without it, but the header keeps the drain’s calls out of your span limits. - Calls made before the drain existed are not sent.
OpenRouter
OpenRouter sends calls to Morse with Broadcast, to an OpenTelemetry destination. Open Workspace → Observability → Traces → OpenTelemetry Collector in OpenRouter and set:
# OpenRouter > Workspace > Observability > Traces > OpenTelemetry Collector
Endpoint: https://api.morseai.dev/api/v1/otlp/v1/traces
Headers: {"Authorization": "Bearer <your environment key>", "X-Morse-Gateway-Kind": "openrouter"}
Privacy: turn on Privacy Mode, so prompts and completions are not sent- Leave the metrics endpoint empty. Under Additional generation metadata, turn on Cost and Identity.
- OpenRouter’s Test Connection is expected to succeed. Morse answers its test request with a success.
- The
X-Morse-Gateway-Kindheader must beopenrouter. - To tag an agent, send
trace: {"morse_agent": "<agent name>"}in the request body.
Other OpenTelemetry gateway
Use this for any gateway that exports OpenTelemetry traces. Kong is the worked example.
# Gateways that read the standard OpenTelemetry exporter environment
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT="https://api.morseai.dev/api/v1/otlp/v1/traces"
OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer%20<your environment key>,X-Morse-Gateway-Kind=otel"
# Kong Gateway 3.14 or later: a global opentelemetry plugin (declarative config)
plugins:
- name: opentelemetry
config:
traces_endpoint: "https://api.morseai.dev/api/v1/otlp/v1/traces"
headers:
Authorization: "Bearer <your environment key>"
X-Morse-Gateway-Kind: "otel"
resource_attributes:
service.name: "kong"
# and on every ai-proxy plugin:
# logging: { log_statistics: true, log_payloads: false }
# In the gateway's own tracing settings, leave prompt and completion capture off.Use one of the two blocks, not both. The environment variables are for most gateways. The plugin block is for Kong.
- The kind header is required. Span attributes alone are not enough to tell a gateway from an SDK-instrumented agent.
- Kong Gateway 3.9 (tested) exports no model or token details. Use 3.14 or later, with
log_statisticsonai-proxy. - Morse names the source from the gateway’s service name. It never creates an agent from it. Assign its calls to agents with attribution rules.
Prompts and completions
By default Morse does not store prompts or completions from a gateway. Every setup snippet also tells your gateway not to send them.
Each gateway has a Capture prompts switch. Turning it on opens a dialog, Store prompts and completions?. Choose Store prompts to confirm, or Keep it off. With it on, the prompts and completions your gateway sends are redacted and stored. Turning it off needs no confirmation.
If a gateway sends bodies while capture is off, the row shows Bodies arriving with capture off. Your gateway is sending prompt or completion text. Morse drops it, because capture is off. To stop it being sent, turn off body logging in the gateway’s settings.
Pause and Resume
Pause stops Morse from recording a gateway’s calls. While a gateway is paused, the events it sends are dropped and counted as dropped. Resume starts recording again. Pausing does not change your gateway.
Gateway status
Each gateway row shows a status and when it was last seen:
| Status | Meaning |
|---|---|
| Waiting for first event | No event has arrived yet. |
| Receiving | Events are arriving. auto-detected means the first event created the row. |
| No events in 24h | Nothing has arrived for 24 hours. Check that the gateway is still exporting. |
| Paused | You paused it. Events are dropped until you resume. |
| Error | The source is in an error state. |
The Last 24h column shows three figures:
- Events received.
- Dropped: events Morse did not store, shown as “N dropped over the X/min rate cap”. See Rate limits.
- Payloads: the bytes of prompt and completion bodies received.
The Matched to SDK (30d) column shows how many of the gateway’s calls in the last 30 days were matched to a call your Morse SDK also traced, for example “23 of 76 · 30%”, with “53 not matched · 23 counted under the SDK” underneath. A matched call is counted once, under the SDK’s trace, so the Spend column covers only the calls that were not matched. When none of the providers this gateway routes had SDK spend in the period, the cell shows ”—” and “No SDK calls to match”: there is nothing to double count. See A call is counted once.
Rate limits
Each gateway has a per-minute rate cap. The cap depends on your plan, and the row shows the cap in force, for example “12 dropped over the 300/min rate cap”. Calls over the cap in a minute are dropped. The next minute starts fresh.
Morse also has a capacity limit that protects the service for every customer. Calls dropped there show as “at Morse’s capacity limit”. If you see it, contact support.
Send the kind header. With X-Morse-Gateway-Kind, your gateway’s calls are counted only
against the gateway rate cap, and every dropped call shows in the row. Without it, an export is
also checked against the span limits your agents’ traces use, which count every span a gateway
sends (about 11 per LiteLLM call). It can then be refused before Morse counts it, and it uses up
budget your agents need. If you set up LiteLLM or Vercel before November 19, 2026, add the header.
A dropped call never affects your traffic: Morse reads the telemetry your gateway exports and is
never in the request path. Your gateway may retry the export after Morse answers 429.
Spend counts stored calls only. When calls were dropped in the last 30 days, the Spend column is marked Incomplete and says how many calls are missing, for example “340 calls were dropped in the last 30 days and are not in this figure”. Check the gateway’s own bill for the full amount. Gateway calls are never billed per call.
Spend per gateway
Each row’s Spend column shows what Morse counts under that gateway over the last 30 days, for example “$0.00021, 11 calls in 30 days”.
A call is counted once
A call can pass through two of your gateways. For example, LiteLLM or Kong routes through OpenRouter, and OpenRouter Broadcast is also connected. Both gateways then report the same call. Morse counts it once, under the first gateway it passed through. That outer gateway holds the agent tag, key alias and team, so attribution stays correct.
When this happens, the Gateways list says so above the table. The second gateway’s row adds a line:
- “N calls ($X) also went through A, counted there”, where A is the outer gateway.
- “Reported by OpenRouter: $X, N calls”. This is that gateway’s own total, duplicates included, so you can check it against its bill.
Your OpenRouter bill therefore includes calls that Morse shows under the outer gateway. The two totals are not meant to match.
When two records of one call disagree on cost, Morse keeps the better one: a cost reported by the provider, then a cost from an aggregator such as OpenRouter, then Morse’s own price for the call.
Morse matches the records by the provider’s response id, when they start within 15 minutes of each other. Matching runs every 5 minutes over the last 30 minutes, so duplicates are usually merged within about 30 minutes. Records up to 30 days old can be reconciled with a backfill pass. A cached response is never merged.
When you also use the Morse SDK. A call your SDK traces and your gateway also reports is counted once when Morse can tell the two records belong together. It can tell in two ways:
- Shared trace context. The Python SDK 0.9.0 or later and the TypeScript SDK 0.8.0 or later add
a W3C
traceparentheader to each model call they trace (OpenAI and Anthropic clients, including calls made through LangChain, LangGraph and the Vercel AI SDK). A gateway that forwards that header reports its record inside your SDK trace, and Morse merges the two as soon as both arrive. Tested with LiteLLM. To stop the SDK sending the header, see Trace context on model calls. - The provider’s response id, when both records carry it, using the matching described above.
With an older SDK, or a gateway that drops the traceparent header, a call can still be counted
twice: streamed LangChain calls carry no response id, for example. When your workspace has SDK spend
for a provider and fewer than 90% of a day’s gateway calls to it matched, Settings → Integrations
→ Gateways shows a notice: “Up to $X of gateway spend in the last 30 days may also be counted by
the SDK”. The amount is a ceiling, the smaller of the unmatched gateway spend and the SDK spend no
gateway call matched, not a measured duplicate. Totals are not adjusted. Upgrade to morse-ai 0.9.0
or @morsehq-dev/sdk 0.8.0 so new calls match; calls already recorded keep the flag until they are
30 days old.
Attribution rules
A gateway call belongs to an agent through an attribution rule. Attribution rules lists your rules with their priority, match, agent and environment.
A rule matches one field:
- Key alias
- Team
- User
- Model
- Agent tag (
metadata.morse_agent)
with one condition: equals, starts with or matches (a regular expression found anywhere in the value). Matching ignores case. A rule can also move matched calls to another environment. Choose Keep as received to leave the environment as it is.
Precedence
Rules run in priority order, lowest number first. The default priority is 100. The first rule that matches decides the agent. Between two rules with the same priority, the older one runs first.
After your rules, one built-in rule runs last: a call tagged metadata.morse_agent with the name of
an existing agent goes to that agent. Morse never creates an agent from a tag. A call that nothing
matches is unattributed.
Preview before you save
The rule form makes you preview a rule before Save rule turns on. The preview says what the rule would move over the last 30 days, such as “Moves $512 over 30 days, 1,840 calls”. It writes nothing. If you change the form, preview again.
When you edit a rule, the preview counts only calls whose agent would change. If none would, it says “No change: every call this rule matches over 30 days already goes to this agent”.
After you save or delete a rule, Morse re-attributes the last 30 days of gateway calls with your current rules. New calls use the rule right away.
Unattributed spend
Unattributed spend shows gateway calls from the last 30 days that no rule assigned to an agent, with a headline such as “$X of $Y gateway spend is not assigned to an agent”, and the share unassigned. It groups them by key alias, team, user and model. A call counted once across two gateways is counted once here too.
A row marked May be counted twice holds calls from a provider and day that carry the possible overlap notice above: some of that spend may already be in your SDK traces. Assigning it to an agent does not remove the double count; upgrading the Morse SDK stops it for new calls. The headline says how much of the unattributed spend this covers.
Each row offers a rule. When a value matches one of your agents’ names, the button reads
Assign to and the agent’s name, and opens the rule form already filled in and previewed. Otherwise
Choose agent opens it for you to pick. Tags with no agent lists metadata.morse_agent values
that match no agent, with Assign to an agent.
If you connected a gateway before gateway ingest was on, Morse may have recorded it as an agent. The Gateways section then offers This is my gateway to convert it. Its traces become gateway calls and are assigned by your rules.
Budget drift
For LiteLLM, you can connect a read-only admin key with Connect read-only admin key on the gateway row. Use a viewer-role key, not your proxy master key. Morse stores it encrypted, never shows it again and sends only read (GET) requests with it.
With a key connected, Morse reads your LiteLLM spend limits daily and compares them with your Morse budgets. Budget drift lists each budget whose gateway limit differs by more than 10%, for example “Morse budget $2,000/month, LiteLLM team cap $5,000”. With none, it says the two are in sync. Morse never changes the limit on your gateway.
Who can change settings
Every member can see the Gateways section. Only organization owners and admins can turn gateway ingest on or off, connect a gateway, pause or resume one, change Capture prompts, manage the read-only key, or add, edit and delete rules.
In a demo workspace none of these changes are allowed, including turning gateway ingest on or off.
Troubleshooting
If no event arrives after 10 minutes, check:
- Endpoint. It must be exactly
https://api.morseai.dev/api/v1/otlp/v1/traces. For LiteLLM, restart the proxy after changing its environment. - Auth. The header must be
Authorization=Bearerfollowed by an active environment key. - Call spans (LiteLLM). Set
USE_OTEL_LITELLM_REQUEST_SPAN=true. - Kind header (OpenRouter and other OpenTelemetry gateways).
X-Morse-Gateway-Kindmust beopenrouterorotel. - Gateway ingest. It must be on for your organization. See Turn on gateway ingest.
- Rate cap. A gateway that shows dropped events is over its cap. See Rate limits.
Related
- Budgets and Forecast: spend through a connected gateway counts in your budgets once.
- OTLP: send traces from your own code over OpenTelemetry.
- Integrations settings: the page that holds the Gateways section.