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 programsThe 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-…- Spec
- OpenAPI JSON · llms.txt
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 appsMCP 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 mcp add --transport http openmayhem \
https://mcp.openmayhem.ai/mcp \
--header "X-OpenMayhem-API-Key: $OPENMAYHEM_API_KEY"Getting started
- 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
- 2Pick a modelFind a model in Markets and copy its ID. The market page shows the price and who sells it.Markets
- 3Send a requestCall the API from your code, or ask your AI app once MCP is set up.The examples are below.
Examples
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.
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".
| To | API header | MCP argument | Example |
|---|---|---|---|
| Require a trust tier or higher | X-Mayhem-Min-Att-Tier | routing.min_attestation_tier | 4 |
| Make sure a long prompt fits (text only) | X-Mayhem-Min-Ctx | routing.min_context_tokens | 131072 |
| Use a specific build of the model | X-Mayhem-Quant | routing.quantization | nvfp4 |
| Use only these sellers, in this order | X-Mayhem-Prefer-Providers | routing.preferred_providers | 64-character seller ID |
| Turn hedging on or off (text only) | X-Mayhem-Hedge | routing.hedge | 1 · true |
| Require a minimum speed | X-Mayhem-Min-Tok-S | routing.min_throughput_tokens_per_second | 20 |
| Wait for a free seller instead of failing | X-Mayhem-Max-Wait-Ms | routing.max_wait_ms | 5000 |
| Cap the cost of a request | X-OpenMayhem-Max-Cost-Usd | max_cost_usd | 0.02 |
| Cap the price per 1M input tokens | X-OpenMayhem-Max-Input-Price-Per-Million-Usd | routing.max_input_price_per_million_usd | 0.10 |
| Cap the price per 1M output tokens | X-OpenMayhem-Max-Output-Price-Per-Million-Usd | routing.max_output_price_per_million_usd | 0.50 |
| Cap the price of a typical request | X-OpenMayhem-Max-Representative-Request-Price-Usd | routing.max_representative_request_price_usd | 0.25 |
| Buy from a proxied seller model field | model | model | proxy/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.
Endpoints and MCP tools
Each entry shows the API endpoint and the MCP tool for the same task.
Chat
APIPOST /v1/chat/completionsMCPchatText replies with tools, JSON output and streaming.
Responses
APIPOST /v1/responsesMCPcreate_responseThe same models in the OpenAI Responses format.
Decisions
APIPOST /v1/decisionsMCPdecideTyped answers such as yes or no, a choice or a score.
Embeddings
APIPOST /v1/embeddingsMCPembedVectors for search and memory.
Images
APIPOST /v1/images/generationsMCPgenerate_imageImages from text. These run as jobs.
Video
APIPOST /v1/videosMCPgenerate_videoClips from text or from a start image. These run as jobs.
Speech
APIPOST /v1/audio/speechMCPgenerate_speechSpoken audio from text.
Transcription
APIPOST /v1/audio/transcriptionsMCPtranscribe_audioText from recorded speech, with timestamps.
Music
APIPOST /v1/music/generationsMCPgenerate_musicSongs and instrumentals.
Workflows
APIPOST /v1/workflowsMCPrun_workflowApproved ComfyUI workflows for images, video and audio.
Models and prices
APIGET /v1/modelsMCPlist_models · get_modelEvery model with its price, sellers and status.
Jobs and results
APIGET /v1/jobs/{id}MCPget_job · cancel_job · get_artifactCheck media jobs, cancel them and download the results.
Show 8 more
Text completion
APIPOST /v1/completionsMCPcomplete_textPlain text completion of a prompt.
Audio
APIPOST /v1/audio/generationsMCPgenerate_audioSound and audio clips from a description.
Estimates
APIPOST /v1/estimatesMCPestimate_requestThe expected and the highest cost of a request before you send it.
Token counts
APIPOST /v1/count_tokensMCPcount_tokensExact token counts for a prompt, at no charge.
Credit and account
APIGET /v1/balanceMCPget_balance · get_profileYour credit balance and your account profile.
Proxied offers
APIGET /v1/proxy/offersMCPlist_proxy_models · get_proxy_model · get_proxy_buyer_policy · list_proxy_metadataOffers 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_profileSaved 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_publishBuild, 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.
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.
For experts
Running your own gatewaydirect peer-to-peer access
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.
mayhem up
mayhem pay stripe
curl http://127.0.0.1:11435/v1/modelsSaved routing profilesfor proxied sellers
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.
What the trust tiers meanT1 to T4
- 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.
