Each recipe gives the goal, the path (MCP server, API or both), working code, what it cost when we ran it and how private it is. Set up once:
export CARPE_API_KEY=cdm_your_key # API → Keys
pip install openai requests # Python recipesCosts below were measured on 2026-11-06 and move with the dynamic price. Before running something large, ask for a quote — it is free: POST /router/quote for text, POST /v1/video/quote for video, /pricing for everything else.
| Recipe | Path | Typical cost | Private? |
|---|---|---|---|
| Cheapest model for a task | MCP · API | under $0.0001 per answer | Your choice |
| Confidential analysis in the TEE | MCP · API | ~$0.0005 per page | Yes — TEE, model that keeps nothing |
| A cheaper coding agent | API | per token — see the Models page | Depends on the model |
| Images: generate, edit, upscale | MCP · API | ~$0.03 for the chain | TEE on /v1 |
| A short video clip | MCP · API | ~$0.10 for 5 s | TEE on /v1 |
| Voice: read aloud, transcribe | MCP · API | ~$0.001 per paragraph | TEE on /v1 |
| Music for a video | MCP · API | ~$0.016 per minute | TEE on /v1 |
| Answer questions on your documents (RAG) | API | ~$0.0001 per question | Your choice |
| Web research with sources | MCP · API | ~$0.006 per question | TEE on /v1 |
| Structured extraction at scale | API | ~$0.0001 per document | Your choice |
| Keep spending under control | MCP · API | free | — |
| An agent that pays for itself (x402) | MCP · API | what it uses, capped on-chain | Your choice |
| A private chat app for a team | API | per message | TEE on /v1 |
Cheapest model for a task
Goal: get a good-enough answer at the lowest price, without testing models by hand.
With the MCP server, run the cheapest_model_for prompt, or just ask: "Find the cheapest model that can translate this into German well, then do it." The assistant shortlists models, quotes each on /v1 and /router with carpe_quote (free), runs the cheapest acceptable one and tells you what it cost and who served it.
With the API, quote first, then send the request to the router — it picks the cheapest market by itself:
import os, requests
from openai import OpenAI
BASE = "https://carpe-diem.xyz/api/operator"
# 1. Free quote: what would 500 tokens in / 300 out cost, on each market?
q = requests.post(f"{BASE}/router/quote", json={"model": "deepseek-v4-flash", "input_tokens": 500, "max_tokens": 300}).json()
print("best:", q["best"]["market"], q["best"]["costUsd"], "USD")
# 2. Run it through the router: the cheapest market serves it.
client = OpenAI(base_url=f"{BASE}/router", api_key=os.environ["CARPE_API_KEY"])
raw = client.chat.completions.with_raw_response.create(
model="deepseek-v4-flash",
messages=[{"role": "user", "content": "Translate into German: The meeting moved to Thursday."}],
)
print(raw.parse().choices[0].message.content)
print("served by", raw.headers.get("x-carpe-route-market"), "for", raw.headers.get("x-carpe-route-cost-usdc"), "USDC")Cost: $0.00003 for this translation (served by OpenRouter when we ran it). Privacy: the router may serve it outside the TEE; add extra_body={"privacy": True} to stay on TEE markets.
Confidential analysis in the TEE
Goal: summarise a contract, a medical letter or internal code without it being kept by anyone.
Use the /v1 surface (always through Carpe's TEE) and a model listed as privacy: "private" in /v1/models — Venice runs those without keeping prompts or answers.
With the MCP server, run the private_inference prompt, or ask: "Privately, inside the TEE only, summarise ./contract.txt in five bullet points." The result says tee: true.
import os, requests
from openai import OpenAI
BASE = "https://carpe-diem.xyz/api/operator"
models = requests.get(f"{BASE}/v1/models").json()["data"]
private = [m["id"] for m in models if m.get("carpe_diem_type") == "text" and m.get("privacy") == "private"]
print(len(private), "private text models, e.g.", private[:3])
client = OpenAI(base_url=f"{BASE}/v1", api_key=os.environ["CARPE_API_KEY"])
document = "This agreement is made between Alpha SA and Beta GmbH. Term: 24 months. Either party may terminate with 90 days' notice."
r = client.chat.completions.create(
model="deepseek-v4-flash", # listed "private"
messages=[
{"role": "system", "content": "You summarise legal documents in five short bullet points."},
{"role": "user", "content": document},
],
)
print(r.choices[0].message.content)Cost: $0.0001 for this summary; count about $0.0005 for a full page. Privacy: TEE end to end on Carpe's side, and a model that keeps nothing. The e2ee-* models go further (end-to-end encrypted to the model's own enclave). Check the attestation at /attestation and on the Privacy page.
A cheaper coding agent
Goal: keep your coding agent, pay less per task.
Point the agent at Carpe and pick a model by price and skill: Claude models for the hardest work, kimi-k2-7-code, qwen3-coder-480b-a35b-instruct-turbo or deepseek-v4-pro for most of it. Step-by-step setup for Claude Code, OpenCode, Aider, Cline, Continue, Zed and VS Code: Coding agents.
Give the same agent the MCP server and it can also produce the assets your project needs — icons, mock-ups, voice-overs — without leaving the terminal.
Cost: you pay per token at Carpe's price, shown live on the Models page; the API space shows what each key spent. Privacy: prefer a private model for proprietary code; Claude models are anonymized.
Images: generate, edit, upscale
Goal: a hero image for a page, then a variant, then a print-size version.
With the MCP server: "Generate a 16:9 flat illustration of a red fox in a forest, then make the fox blue, then upscale it ×2. Save everything in ./assets." — carpe_image_generate, carpe_image_edit, carpe_image_upscale.
import base64, os, time, requests
BASE = "https://carpe-diem.xyz/api/operator/v1"
H = {"Authorization": f"Bearer {os.environ['CARPE_API_KEY']}"}
def queued(path, body):
"""Queue a slow image job, poll until the image comes back (binary)."""
qid = requests.post(f"{BASE}/{path}/queue", headers=H, json=body).json()["queue_id"]
while True:
r = requests.post(f"{BASE}/{path}/retrieve", headers=H, json={"queue_id": qid})
if r.headers.get("content-type", "").startswith("image/"):
return r.content
if r.json().get("status") != "pending":
raise RuntimeError(r.text)
time.sleep(2)
# 1. Generate (synchronous for fast models) → base64 WebP
gen = requests.post(f"{BASE}/image/generate", headers=H, json={
"model": "z-image-turbo", "prompt": "a red fox in a forest, flat illustration",
}).json()
fox = gen["images"][0]
open("fox.webp", "wb").write(base64.b64decode(fox))
# 2. Edit (queued: edit models take longer) — the source goes in as a data URI
blue = queued("image/edit", {
"model": "qwen-image-2-1-turbo-edit", "prompt": "make the fox blue",
"image": f"data:image/webp;base64,{fox}",
})
open("fox-blue.png", "wb").write(blue)
# 3. Upscale ×2: raw base64, no data: prefix
up = requests.post(f"{BASE}/image/upscale", headers=H, json={
"model": "upscaler", "image": base64.b64encode(blue).decode(), "scale": 2,
}, timeout=180)
up.raise_for_status()
open("fox-blue-2x.png", "wb").write(up.content)
print("cost of the last step:", up.headers.get("x-carpe-cost-usdc-micro"), "µUSDC")Cost: about $0.005 to generate, $0.011 to edit and $0.011 to upscale ×2. Privacy: on /v1, through the TEE. A model too slow for a single request answers 409 MODEL_REQUIRES_ASYNC with the endpoint to use: the queued() helper above works for image/generate, image/edit and image/multi-edit (queue reference).
A short video clip
Goal: a 5-second clip for a post or a landing page.
With the MCP server: "Make a 5-second 16:9 clip of a paper boat on a calm lake. Quote it first." — carpe_video_generate quotes, queues, then carpe_video_status waits and saves the MP4.
import os, time, requests
BASE = "https://carpe-diem.xyz/api/operator"
H = {"Authorization": f"Bearer {os.environ['CARPE_API_KEY']}"}
job = {"model": "grok-imagine-1-5-lite-text-to-video", "prompt": "a paper boat on a calm lake, morning light",
"duration": "5s", "aspect_ratio": "16:9"}
print("quote:", requests.post(f"{BASE}/v1/video/quote", headers=H, json=job).json()["cost_usdc"], "USD")
qid = requests.post(f"{BASE}/v1/video/queue", headers=H, json=job).json()["queue_id"]
while True:
r = requests.post(f"{BASE}/v1/video/retrieve", headers=H, json={"queue_id": qid}).json()
if r["status"] == "completed":
url = r.get("video_url") or r.get("url")
video = requests.get(url if url.startswith("http") else BASE + url) # kept ~10 minutes
open("boat.mp4", "wb").write(video.content)
break
if r["status"] == "failed":
raise RuntimeError(r)
time.sleep(5)Cost: $0.097 for these 5 seconds, exactly the quote (models range from cents to dollars: always quote first). Durations, aspect ratios and resolutions differ per model: read them from constraints in /v1/models. Privacy: on /v1, through the TEE. Download the file as soon as it is ready.
Voice: read aloud, transcribe
Goal: turn a paragraph into an MP3, and an audio file back into text.
With the MCP server: "Read this paragraph aloud in French and save the MP3. Then transcribe it to check." — carpe_tts, carpe_transcribe.
import os, requests
BASE = "https://carpe-diem.xyz/api/operator/v1"
H = {"Authorization": f"Bearer {os.environ['CARPE_API_KEY']}"}
speech = requests.post(f"{BASE}/audio/speech", headers=H, json={
"model": "tts-kokoro", "input": "Bonjour ! Ceci est un test de synthèse vocale.", "response_format": "mp3",
})
speech.raise_for_status()
open("hello.mp3", "wb").write(speech.content)
text = requests.post(f"{BASE}/audio/transcriptions", headers=H,
files={"file": ("hello.mp3", speech.content, "audio/mpeg")},
data={"model": "openai/whisper-large-v3"}).json()
print(text["text"])Cost: $0.0003 for this sentence, both steps (speech is billed per character, transcription per minute of audio). Voices are per model: omit voice for the default, or pick one from the model's voices in /v1/models. Privacy: on /v1, through the TEE. Cloning a voice (carpe_voice_clone, POST /v1/audio/voices) requires the speaker's consent and is kept 7 days by the provider.
Music for a video
Goal: a background track sized to your clip.
With the MCP server: "Compose a 60-second calm lo-fi piano track, instrumental, and save it." — carpe_music_generate, carpe_music_status.
import os, time, requests
BASE = "https://carpe-diem.xyz/api/operator/v1"
H = {"Authorization": f"Bearer {os.environ['CARPE_API_KEY']}"}
qid = requests.post(f"{BASE}/audio/music/queue", headers=H, json={
"model": "ace-step-15", "prompt": "calm lo-fi piano loop, warm, slow", "duration_seconds": 60,
}).json()["queue_id"]
while True:
r = requests.post(f"{BASE}/audio/music/retrieve", headers=H, json={"queue_id": qid, "model": "ace-step-15"})
if r.headers.get("content-type", "").startswith("audio/"):
open("track.flac", "wb").write(r.content) # ace-step-15 delivers FLAC; a /v1 track can be fetched once
break
if r.json().get("status") == "failed":
raise RuntimeError(r.text)
time.sleep(5)Cost: about $0.016 for 60 seconds on ace-step-15. Each music model accepts different lengths, options and file formats (duration_options, supports_lyrics, default_format…): read its constraints in /v1/models first. Privacy: on /v1, through the TEE.
Answer questions on your documents (RAG)
Goal: a small question-answering bot over your own notes.
import os, math
from openai import OpenAI
client = OpenAI(base_url="https://carpe-diem.xyz/api/operator/v1", api_key=os.environ["CARPE_API_KEY"])
docs = [
"Refunds are possible within 30 days of purchase.",
"Support answers in English and French, Monday to Friday.",
"Enterprise plans include a dedicated account manager.",
]
def embed(texts):
r = client.embeddings.create(model="text-embedding-bge-m3", input=texts)
return [d.embedding for d in r.data]
def cos(a, b):
return sum(x * y for x, y in zip(a, b)) / (math.sqrt(sum(x * x for x in a)) * math.sqrt(sum(y * y for y in b)))
index = embed(docs)
question = "Can I get my money back after three weeks?"
q = embed([question])[0]
best = max(range(len(docs)), key=lambda i: cos(q, index[i]))
answer = client.chat.completions.create(
model="deepseek-v4-flash",
messages=[
{"role": "system", "content": f"Answer only from this context: {docs[best]}"},
{"role": "user", "content": question},
],
)
print(answer.choices[0].message.content)Cost: $0.00015 for this question, embeddings included; embedding a large document set once costs a fraction of a cent per hundred pages. Privacy: both calls on /v1, through the TEE; text-embedding-bge-m3 and deepseek-v4-flash are private models. The same works with LangChain or LlamaIndex.
Web research with sources
Goal: a short, sourced answer about something recent.
With the MCP server: "Search the web for the latest Base network upgrade and summarise it with sources." — carpe_web_search, carpe_web_scrape, then carpe_chat.
import os, requests
from openai import OpenAI
BASE = "https://carpe-diem.xyz/api/operator/v1"
H = {"Authorization": f"Bearer {os.environ['CARPE_API_KEY']}"}
results = requests.post(f"{BASE}/augment/search", headers=H, json={"query": "Base network latest upgrade"}).json()["results"][:5]
context = "\n\n".join(f"[{i + 1}] {r['title']} ({r['url']})\n{r['content']}" for i, r in enumerate(results))
client = OpenAI(base_url=BASE, api_key=os.environ["CARPE_API_KEY"])
r = client.chat.completions.create(
model="deepseek-v4-flash",
messages=[
{"role": "system", "content": "Answer from the sources below and cite them as [n].\n\n" + context},
{"role": "user", "content": "What changed in the latest Base network upgrade?"},
],
)
print(r.choices[0].message.content)To read a full page, POST /v1/augment/scrape with {"url": "https://…"} returns its content. Cost: $0.0054 per search or scrape, plus the answer ($0.0056 in all for this one). Privacy: on /v1, through the TEE; the search itself goes to the web.
Structured extraction at scale
Goal: turn thousands of emails, invoices or tickets into clean JSON, cheaply and without double billing on retries.
import json, os, uuid
from openai import OpenAI
client = OpenAI(base_url="https://carpe-diem.xyz/api/operator/router", api_key=os.environ["CARPE_API_KEY"], max_retries=3)
schema = {
"name": "invoice",
"strict": True,
"schema": {
"type": "object",
"properties": {
"vendor": {"type": "string"},
"total": {"type": "number"},
"currency": {"type": "string"},
"due_date": {"type": "string"},
},
"required": ["vendor", "total", "currency", "due_date"],
"additionalProperties": False,
},
}
def extract(text: str) -> dict:
r = client.chat.completions.create(
model="deepseek-v4-flash",
messages=[{"role": "user", "content": f"Extract the invoice fields:\n\n{text}"}],
response_format={"type": "json_schema", "json_schema": schema},
# Same key on a retry → the router replays the first answer instead of billing twice.
extra_headers={"Idempotency-Key": str(uuid.uuid5(uuid.NAMESPACE_URL, text))},
)
return json.loads(r.choices[0].message.content)
print(extract("ACME Corp — Invoice 1042 — Total due: 1,250.00 EUR by 2026-12-01."))Cost: $0.00004 for this invoice on the router. Privacy: the router may serve it outside the TEE: add extra_body={"privacy": "private"} for markets that keep nothing (the idempotent replay is then off), or use /v1. Keep under the rate limits: read yours with GET /v1/rate_limits.
Keep spending under control
Goal: know where the money goes, and make sure an agent cannot run away with it.
- Per key: create one key per app or agent in API → Keys, so each one's spend is separate (
GET /buyer/api-keys/usage). - In the MCP server:
CARPE_MAX_PER_CALL_USDandCARPE_MAX_SPEND_USDrefuse a call before it is sent;CARPE_READ_ONLY=1for an assistant that should only look things up. - Reports: run the
cost_reportprompt, or ask "How much did I spend this week, on which models, and how much did the router save?". With the API:
curl -s https://carpe-diem.xyz/api/operator/v1/credits -H "Authorization: Bearer $CARPE_API_KEY"
curl -s "https://carpe-diem.xyz/api/operator/buyer/usage/summary?days=7" -H "Authorization: Bearer $CARPE_API_KEY"
curl -s "https://carpe-diem.xyz/api/operator/buyer/routing/summary" -H "Authorization: Bearer $CARPE_API_KEY"- Every response carries its cost (
X-Carpe-Cost-Usdc-Microon/v1,X-Carpe-Route-Cost-Usdcon/router) and your remaining balance (X-Carpe-Available-Credits), so an app can stop itself. - If a key leaks: revoke it in API → Keys, or let the key revoke itself:
POST /v1/keys/self/revoke(the MCP toolcarpe_revoke_this_key).
An agent that pays for itself (x402)
Goal: an autonomous agent with its own wallet and a hard budget — no account, no key to manage.
Fund a dedicated wallet with a little USDC on Base, then give its private key to the MCP server with a budget:
{
"mcpServers": {
"carpe": {
"command": "npx",
"args": ["-y", "carpe-diem-mcp"],
"env": {
"CARPE_X402_PRIVATE_KEY": "0xYOUR_AGENT_WALLET_KEY",
"CARPE_X402_BUDGET_USD": "2",
"CARPE_MAX_PER_CALL_USD": "0.25"
}
}
}
}The server signs one USDC permit whose value is the budget: Carpe can never pull more than $2 in total, whatever the agent does, and the spend is remembered across restarts. carpe_x402_status shows the wallet, its USDC and what is left. To do it from your own code, see x402 in the API reference.
Cost: what the agent uses, at the same prices. Privacy: no account, no email: the wallet is the identity.
A private chat app for a team
Goal: a ChatGPT-like app for your team, on models you choose, without each person needing an account anywhere.
Deploy Open WebUI or LibreChat with one Carpe key (or one key per user with LibreChat's user_provided). Point it at https://carpe-diem.xyz/api/operator/v1 so every conversation goes through the TEE, and leave only private models visible for confidential work. Give the app the MCP server too (LibreChat) and people can ask for images, voice and web research from the same chat.
Cost: per message, at Carpe's price; track it per key in API → Usage. Privacy: on /v1, through the TEE; with private models nothing is kept by the model provider.