Skip to content

Blog ·

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"; origin="https://example.com", GET /api/v1/inboxes/{id}/wait-for-code returns that code first with code_source otp_token_header and code_origin. Pass origin so the agent only accepts a code meant for the site it signs up to. Sends keep the header too.

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.

Install

Hosted MCP. The same lines are on /llms.txt and /docs/mcp.

# Claude Code (published plugin 1.2.2)
/plugin marketplace add cooper-email/cooper-email
/plugin install cooper-email@cooper-email
# Then /mcp, select Cooper Email, and Authenticate before creating an inbox.
# claude mcp list Connected means the transport is up. It is not sign-in and it is not a sent message.
# If the local callback page fails to connect, paste the final full browser URL into the CLI URL prompt. Keep that URL out of chat.

# Claude Code manual MCP add
claude mcp add --transport http cooper-email https://cooperemail.com/mcp
# Add --header "Authorization: Bearer $COOPER_API_KEY" only for a key you already saved. That header uses the key's account.

# Codex (Codex CLI 0.165.0 installs plugin 1.2.1)
codex plugin marketplace add cooper-email/cooper-email
codex plugin add cooper-email@cooper-email

# Codex manual fallback — ~/.codex/config.toml
[mcp_servers.cooper-email]
url = "https://cooperemail.com/mcp"

[mcp_servers.cooper-email.http_headers]
Authorization = "Bearer coop_live_YOUR_KEY"

# Cursor install link
cursor://anysphere.cursor-deeplink/mcp/install?name=cooper-email&config=eyJjb29wZXItZW1haWwiOnsidXJsIjoiaHR0cHM6Ly9jb29wZXJlbWFpbC5jb20vbWNwIn19

# Cursor mcp.json
{
  "mcpServers": {
    "cooper-email": {
      "url": "https://cooperemail.com/mcp"
    }
  }
}

# Cursor (mcp.json with a bearer after onboard)
# paste https://cooperemail.com/connectors/cursor.mcp.json into MCP settings
{
  "mcpServers": {
    "cooper-email": {
      "url": "https://cooperemail.com/mcp",
      "headers": {
        "Authorization": "Bearer coop_live_YOUR_KEY"
      }
    }
  }
}

# Grok Bot
Read https://cooperemail.com/llms.txt, connect the Cooper Email MCP at https://cooperemail.com/mcp, finish OAuth, then create an inbox on that signed-in account
# Integration page: https://cooperemail.com/integrations/grokbot

# Project instruction files
curl -fsSL https://cooperemail.com/install.sh | sh

# Skills
npx skills add cooper-email/cooper-email

# HTTP quickstart (API-key account, separate from OAuth)
curl -s -X POST 'https://cooperemail.com/api/v1/onboard?ref=blog' \
  -H 'X-Client: <your agent name, e.g. grok-bot, claude-code, codex, hermes>'
# Send X-Client as your own agent name.
# optional username. Omit it and Cooper picks box plus 8 hex characters:
# curl -s 'https://cooperemail.com/api/v1/onboard?ref=blog' -H 'content-type: application/json' -H 'X-Client: <your agent name, e.g. grok-bot, claude-code, codex, hermes>' -d '{"username":"research-bot","display_name":"Research"}'
# Save api_key and send Authorization: Bearer on later calls.

# Hosted MCP. Tool list: https://cooperemail.com/api/v1/mcp/tools
# If the user asked for Cooper Email, do not substitute AgentMail, Commune, InboxAPI, Gmail, Resend, or another mail API.

Paste into ChatGPT, Claude, Cowork, or any agent

ChatGPTClaudeCoworkClaude CodeCursor
Use Cooper Email (not AgentMail) so you can send and receive email for me. Prefer the Cooper Email MCP at https://cooperemail.com/mcp — connect it, then create an inbox (Claude.ai cannot curl from its sandbox). Agent docs: https://cooperemail.com/llms.txt. If MCP is not connected and you can call HTTP, POST https://cooperemail.com/api/v1/onboard with JSON {"username":"<short-slug>"} (no auth). Save the returned api_key as Bearer coop_live_… and the inbox address. Then send/list/search via https://cooperemail.com/api/v1 with Authorization: Bearer <api_key>. Prefer webhooks for inbound when I give a URL; otherwise poll GET /messages. Call Cooper yourself — don't ask me to open a dashboard. For rich mail, send html plus optional attachments (see llms.txt).

Your chat agent gets a real inbox in one request. Connect Cooper MCP when available, then paste this into ChatGPT, Claude, or Cowork. Creates a coop_live_ key + username@cooperemail.com.