Use OpenMayhem from your code or your AI app

Programs call our OpenAI-compatible API, and AI apps such as Claude, Codex and Cursor connect to our MCP server. Both use the same account and credit, with the same models, prices and receipts.

API

For programs

The API works with the OpenAI SDKs. Point them at the base URL and use a model ID from Markets.

Base URL
https://api.openmayhem.ai/v1
Key
Authorization: Bearer sk-om-v1-…
curl
curl https://api.openmayhem.ai/v1/chat/completions \
  -H "Authorization: Bearer $OPENMAYHEM_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"qwen/qwen3.8-flash-next",
       "messages":[{"role":"user","content":"Hello"}]}'

MCP

For AI apps

MCP is the standard way for AI apps to use outside tools. After you add our server, your assistant can look up models and prices and run chat, image, video, speech and music requests. It pays from your credit.

Server
https://mcp.openmayhem.ai/mcp
Sign in
Apps that support MCP sign-in, such as ChatGPT, open an OpenMayhem page where you approve the access and set spending limits. Other apps send your API key in a header.
Claude Code
claude mcp add --transport http openmayhem \
  https://mcp.openmayhem.ai/mcp \
  --header "X-OpenMayhem-API-Key: $OPENMAYHEM_API_KEY"

Getting started

  1. 1Create a keyIn your dashboard, create an API key, choose what it may be used for and set spending limits. The key is shown only once.Dashboard, API keys
  2. 2Pick a modelFind a model in Markets and copy its ID. The market page shows the price and who sells it.Markets
  3. 3Send a requestCall the API from your code, or ask your AI app once MCP is set up.The examples are below.

Examples

API
MCP
curl
curl https://api.openmayhem.ai/v1/chat/completions \
  -H "Authorization: Bearer $OPENMAYHEM_API_KEY" \
  -H "Content-Type: application/json" \
  -H "X-OpenMayhem-Max-Cost-Usd: 0.02" \
  -d '{
    "model": "qwen/qwen3.8-flash-next",
    "messages": [{ "role": "user", "content": "Three names for a bakery by the sea" }]
  }'

From code

The response has the usual OpenAI format, plus the exact cost in USD and the ID of the signed receipt. The cost header is optional. A request that could cost more is refused before anything is charged.

MCP setup for every app

Choosing who serves a request

If you send none of these, the network chooses a seller for you. In an AI app you can ask in plain words, for example "use only T4 sellers and spend at most 2 cents".

ToAPI headerMCP argumentExample
Require a trust tier or higherX-Mayhem-Min-Att-Tierrouting.min_attestation_tier4
Make sure a long prompt fits (text only)X-Mayhem-Min-Ctxrouting.min_context_tokens131072
Use a specific build of the modelX-Mayhem-Quantrouting.quantizationnvfp4
Use only these sellers, in this orderX-Mayhem-Prefer-Providersrouting.preferred_providers64-character seller ID
Turn hedging on or off (text only)X-Mayhem-Hedgerouting.hedge1 · true
Require a minimum speedX-Mayhem-Min-Tok-Srouting.min_throughput_tokens_per_second20
Wait for a free seller instead of failingX-Mayhem-Max-Wait-Msrouting.max_wait_ms5000
Cap the cost of a requestX-OpenMayhem-Max-Cost-Usdmax_cost_usd0.02
Cap the price per 1M input tokensX-OpenMayhem-Max-Input-Price-Per-Million-Usdrouting.max_input_price_per_million_usd0.10
Cap the price per 1M output tokensX-OpenMayhem-Max-Output-Price-Per-Million-Usdrouting.max_output_price_per_million_usd0.50
Cap the price of a typical requestX-OpenMayhem-Max-Representative-Request-Price-Usdrouting.max_representative_request_price_usd0.25
Buy from a proxied seller model fieldmodelmodelproxy/offer/<market>/<provider>/<slot>

The MCP arguments sit inside the routing object of a paid tool. max_cost_usd is a separate argument, and every paid tool requires it.

A proxied offer ID has three 64-character parts. The request also needs the proxy object that a saved routing profile returns when you resolve it. Proxied offers never receive native requests, and native sellers never receive proxied ones. Proxied requests accept the cost cap, minimum context, minimum speed and seller list from this table.

Routing in detailBuying from proxied sellers

Endpoints and MCP tools

Each entry shows the API endpoint and the MCP tool for the same task.

Show 8 more
  • Text completion

    APIPOST /v1/completionsMCPcomplete_text

    Plain text completion of a prompt.

  • Audio

    APIPOST /v1/audio/generationsMCPgenerate_audio

    Sound and audio clips from a description.

  • Estimates

    APIPOST /v1/estimatesMCPestimate_request

    The expected and the highest cost of a request before you send it.

  • Token counts

    APIPOST /v1/count_tokensMCPcount_tokens

    Exact token counts for a prompt, at no charge.

  • Credit and account

    APIGET /v1/balanceMCPget_balance · get_profile

    Your credit balance and your account profile.

  • Proxied offers

    APIGET /v1/proxy/offersMCPlist_proxy_models · get_proxy_model · get_proxy_buyer_policy · list_proxy_metadata

    Offers from proxied sellers with their prices and terms.

  • Routing profiles

    APIPOST /v1/proxy/profiles/{id}/resolveMCPlist_proxy_profiles · get_proxy_profile · resolve_proxy_profile · prepare_proxy_profile

    Saved rules for buying from proxied sellers.

  • Playbay games

    APIOnly through MCPMCPplaybay_contract · playbay_validate · playbay_check · playbay_read · playbay_product · playbay_build · playbay_test · playbay_publish

    Build, test and publish Playbay games from an AI app.

Checking the cost

You can ask for an estimate before you send a request. Every response includes its exact cost in USD and the ID of a signed receipt. The price is fixed when a request starts, and a request that no seller can serve within your limits stops before anything is charged.

Limits for each key

Every key has its own list of allowed tasks, models and limits per request and per day, week or month. An agent that misbehaves stops at its key's limit and cannot spend your whole balance.

Keys and limits

Payment

You buy credit by card, and you can also pay with TNK or TAP. You do not need any cryptocurrency. The same balance pays for the API, MCP and Chat.

Privacy of prompts

Requests are encrypted while they travel. Most sellers process prompts in their normal runtime. T3 sellers use confidential computing, which keeps prompts private while they run.

Apps built for OpenAI

Most apps and SDKs built for OpenAI work after you change the address and the key. A few OpenAI features have no exact match yet. The endpoint reference lists what each endpoint supports.

Endpoint reference

For experts

Running your own gateway

If you install OpenMayhem Core and run mayhem up, you get the same API at http://127.0.0.1:11435/v1. Requests then go straight to sellers over encrypted peer-to-peer connections. The README on GitHub has a prompt that lets a coding agent do the install.

shell
mayhem up
mayhem pay stripe
curl http://127.0.0.1:11435/v1/models
Saved routing profiles

A profile stores your rules for buying from proxied sellers: which offer or category, which sellers, how you pay and your price limits. You create and change profiles on the website or in Chat. The API and MCP can read and resolve them.

Buying from proxied sellers

What the trust tiers mean
  • T1: the seller signs a record of what ran and what it cost.
  • T2: the request runs on a machine that has proved its hardware identity.
  • T3: the request runs on confidential hardware, so the prompt stays private while it is processed.
  • T4: the seller is a business that OpenMayhem has verified and names publicly.
Errors, streaming and jobs