Skip to main content

OTP-Token header: how an AI agent reads the right verification code from email

Cooper Email's wait-for-code now reads the OTP-Token email header from IETF draft-goto-otp-token-01. When a sign-up email carries OTP-Token: \"123456\

Updated 7 min readMarkdown

A sign-up email that says "Your code is 482913" is written for a person. An agent has to find the digits in the text, guess which number is the code and not an order number, and trust that the email came from the site it is signing up to. Mostly that works. Sometimes it picks the wrong number, or a code from a different site that landed in the same inbox a few seconds earlier.

A new email header fixes the first part and helps with the second. On November 24, Resend published The future of email verification, a walk through the OTP-Token header proposed in the IETF Internet-Draft draft-goto-otp-token-01. The header puts the code and the origin it belongs to in one machine-readable line:

OTP-Token: "123456"; origin="https://example.com"

As of November 25, Cooper Email reads that header when your agent waits for a code, and keeps it on mail your agent sends.

Cooper Email is HTTP email for autonomous agents. One public POST https://cooperemail.com/api/v1/onboard returns a Bearer api_key and username@cooperemail.com. Machine-readable source: https://cooperemail.com/llms.txt. Hosted MCP: https://cooperemail.com/mcp. Prices: https://cooperemail.com/pricing. Endpoint reference: https://cooperemail.com/docs/reference/inbox-wait-for-code. This post is https://cooperemail.com/blog/otp-token-header-ai-agent-verification-codes.

If you are new to wait-for-code itself (the long poll, kind=link, plus-address aliases, timeouts), start with How can my agent poll an inbox for a verification code?. This post covers only what the header adds.

What the draft says

The draft is short. The parts that matter to an agent:

  • The value is a quoted code plus a required origin parameter.
  • The origin must be canonical (lowercase, no default port, no path), must not be null, and must be potentially trustworthy: https, or a local address such as http://localhost.
  • A message may carry the header at most once in its top-level headers. A copy inside a MIME body part must be ignored.

It is an early draft. It may change or never become an RFC, and today few senders set it. The point of the origin is phishing resistance: software that hands the code to a page can check that the page's origin matches the one in the header, the same way origin-bound SMS codes work in browsers.

For an agent the origin answers a simpler question: is this code for the site I am signing up to right now?

Reading the header with wait-for-code

Nothing changes in the call you already make. The agent submits its Cooper address on a sign-up form, then holds:

curl -s "https://cooperemail.com/api/v1/inboxes/$INBOX_ID/wait-for-code?wait=55" \
  -H "Authorization: Bearer $COOPER_API_KEY"

When the email has a valid top-level OTP-Token header, its code is code and it is first in candidates, ahead of anything the text scan found. Two fields tell the agent where the code came from:

{
  "object": "inbox_code",
  "inbox_id": "inb_example",
  "timed_out": false,
  "code": "739184",
  "code_source": "otp_token_header",
  "code_origin": "https://example.com",
  "candidates": ["739184", "482913"],
  "link": null,
  "links": [],
  "message": {
    "id": "msg_example",
    "thread_id": "thr_example",
    "from": "Example <no-reply@example.com>",
    "subject": "Your Example verification code",
    "created_at": "2026-11-25T12:00:00.000Z",
    "channel": "email",
    "alias": null
  },
  "after": "2026-11-25T11:55:00.000Z"
}

In that response the header said 739184 and the body text also contained 482913. The header wins.

  • code_source is otp_token_header when the code came from a valid header, text when it came from the existing body scan, and null on a timeout.
  • code_origin is the header's origin, or null when the code came from text or nothing matched.

When the header is missing or bad, behavior is exactly what it was before: Cooper scans the text for a 4 to 8 digit code (or 123-456) next to a word such as code, OTP, verification, passcode, or PIN, and returns code_source: "text". A malformed value, an origin that is not potentially trustworthy, more than one top-level OTP-Token, or a header inside a MIME part is ignored, not an error. Your agent does not need a second code path for old-style emails.

Inbound message JSON gets the same two fields: when verification.codes is non-empty, verification also carries code_source and code_origin.

Only accept a code for the site you are on

The new query parameter is origin. With it, wait-for-code matches only a message whose valid OTP-Token origin is exactly that value:

curl -s "https://cooperemail.com/api/v1/inboxes/$INBOX_ID/wait-for-code?wait=55&origin=https://example.com" \
  -H "Authorization: Bearer $COOPER_API_KEY"

Three outcomes:

  1. A message with OTP-Token: "739184"; origin="https://example.com" arrives. The call returns code: "739184", code_source: "otp_token_header", code_origin: "https://example.com".
  2. Only messages for other origins, or with no header, arrive. Nothing matches, and the call returns timed_out: true with code: null when the wait ends. Call again or fall back.
  3. The origin itself is not canonical, for example http://example.com or https://example.com/signup. The call fails right away:
{
  "error": {
    "type": "invalid_request",
    "code": "invalid_origin",
    "message": "origin must be a canonical potentially trustworthy origin, such as https://example.com or http://localhost.",
    "param": "origin"
  }
}

The fix is to send the scheme and host only, with no path and no default port. The live response also includes docs_url, which points at the error-code list.

A practical pattern for an agent that signs up to many services from one inbox:

  • Pass origin when you know the site's origin. If the sender sets OTP-Token, you get a code bound to that site and nothing else.
  • If that times out, call once more without origin and with from (a substring of From, such as the service's domain) and after (the time you asked for the code). That catches senders that do not set the header yet.
  • Check code_source before you submit. otp_token_header with the expected code_origin is the strongest match Cooper can give you.

Through MCP

MCP clients get the same thing through cooper_wait_for_code. The tool takes an optional origin input next to inbox_id, wait, after, from_contains, subject_contains, alias, and kind, and returns the same inbox_code object with code_source and code_origin. A bad origin fails with invalid_origin. No new tools were added. The hosted server is https://cooperemail.com/mcp.

The header is still untrusted data

An email header is text the sender wrote. Any sender can claim any origin, and the draft's own security section is still a to-do. Cooper does not open links and does not treat the header as proof of who sent the mail. What it does is narrow the match: with origin, a code that claims a different site never comes back to your agent. Combine it with from and after for the tightest filter, and only use a code for a sign-up your agent actually started.

Sending the header from a Cooper inbox

If your agent sends verification codes, for example to confirm a user's address for its own service, it can set the header on the send. Pass it in headers on POST /api/v1/inboxes/{id}/messages:

curl -s https://cooperemail.com/api/v1/inboxes/$INBOX_ID/messages \
  -H "Authorization: Bearer $COOPER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "to": "user@example.org",
    "subject": "Your Example verification code",
    "text": "Your Example verification code is 739184.",
    "headers": { "OTP-Token": "\"739184\"; origin=\"https://example.com\"" }
  }'

Cooper keeps the header on the outgoing message. For sends the rule is stricter than for reading: the value must be one header with a quoted code and a canonical https origin. A missing origin, a second OTP-Token, or an origin that is not canonical https returns HTTP 400 invalid_headers with param: "headers", and nothing is sent. From, To, Subject, and Message-ID are unchanged.

A Cooper inbox that receives that message gets code_source: "otp_token_header" back from wait-for-code, so two agents on Cooper can hand codes to each other without parsing prose.

What changed, in one list

  • GET /api/v1/inboxes/{id}/wait-for-code and cooper_wait_for_code read a valid top-level OTP-Token header and rank its code first.
  • New response fields code_source and code_origin.
  • New optional origin filter; a bad value is HTTP 400 invalid_origin.
  • Sends keep a valid OTP-Token header; a bad one is HTTP 400 invalid_headers.
  • No new MCP tools, no migration, no price change. Details: https://cooperemail.com/changelog and https://cooperemail.com/docs.md.

Cooper Email is operated by Avatar 8 LLC, ops@avatar33.com.


Originally published on Cooper Email.

About the author

  • Real email inboxes for AI agents, via API and MCP. By Avatar 8 LLC.

No comments yet. Be the first to comment.

More from this blog