Set up Darwin Agentic Trading
Using an AI agent? Paste this into it:
Set up Darwin Agentic Trading using https://darwin.finance/agents/setup.md and save the API key so you can trade later./agents/setup.md. Fetch that instead of parsing this page.On this page
> If your browse tool returns a summary, fetch this file raw (e.g. curl) and read all of it.
Which way fits you#
Which way fits you? It depends on where you run. In a chat app (Claude.ai, ChatGPT, Claude Cowork) that can't keep a key: don't pair; tell your user to add https://mcp.darwin.finance/mcp as a custom connector in the app, sign in to Darwin and choose what it can do (the app holds no key). Running code (Claude Code, Codex, OpenClaw, a script or a server): pair as below. Every key reads all of Darwin's market data. Your key's permissions says if your user made it trade all their agents; then send X-Darwin-Agent: <agent id> on every account call (GET /api/agent/v1/agents lists them). To read your user's whole account: a separate API key your user makes with Connect an AI (https://darwin.finance/agents?create=1), never this setup. No Darwin credential can withdraw from an agent or move funds between your user's accounts (an agent's own perps collateral moves are allowed).
Before you start#
- First: Before you pair, check that you can keep the key: in your platform's secret store, or in a file you are allowed to write that will still be there in a later session. If you can't (your platform does not let you write credentials, or your workspace is temporary and gets reset), do not start pairing — Darwin shows a key only once. Instead tell your user, in one or two sentences, that this app can't keep a Darwin key yet, and suggest running setup from an AI agent on their own computer (Claude Code, Codex, Hermes, or any agent with the Darwin skill:
npx skills add DarwinFinance/agent-skills), or creating an API key on their agent's Manage tab and giving it to you for this session only, as a downloaded key file (never pasted into the chat). If your user is in a chat app such as Claude or ChatGPT, the easiest way is Darwin's connector, which needs no key: they addhttps://mcp.darwin.finance/mcpas a custom connector in that app's settings, sign in to Darwin when it asks, and choose what it can do: create a new Agentic Sub-Account for it, trade out of one or all of their existing ones, or read only. (If your user said not to save the key, holding it in memory for this session is what they asked for.) - Your user asked for this. Pasting the setup line is your user's request to connect you to Darwin. Once you know you can keep the key, Step 1 (asking for a pairing code) changes nothing in their account, moves no money and needs no secret, so you do not need to ask before doing it.
- Your user approves in their own browser, with their passkey (and second factor, if they use 2FA). Nothing is granted until they do, and the key can only trade inside one Darwin agentic account. It can never withdraw or transfer funds out.
- Save the key — your user asked you to. The setup line your user pasted ends "and save the API key so you can trade later", so keeping the key beyond this session is their explicit request. Store it securely: in your platform's secret store if it has one; otherwise in a file only your user's account can read (
chmod 600) inside your own workspace, if that workspace persists. Never writedevice_codeanywhere. - Keep it in memory only if your user said not to save it, or their message did not ask you to save it (you may ask them whether to). Then, in your short note after the welcome, tell your user in one sentence that they will need to pair again next session. If your user asked you to save it and you can't, do not pair (see the first point). If your platform does not let you handle the key at all, stop and tell your user.
- Blocked after pairing? If you have already paired and your platform blocks saving the key, respect that: do not store it some other way, and do not put it in a temporary file. In the same command that received it, call GET /api/agent/v1/hello with the key you hold in memory and show your user the
welcome, then tell them the key won't be kept after this session. A single command can poll pair/token, call /hello and print the welcome without writing the key anywhere. - Don't ask; report. Once you know you can keep the key, your user does not need to choose how it is stored before you pair. Go ahead, then tell them where the key lives in your short note after the welcome (see "After setup").
- Given a key file instead? You don't need to pair: see "If your owner gives you a key file" below.
- What your user sees: a link and a code in this chat. In their browser they open the link, check the code and approve. Darwin already knows what this connects: a new Agentic Sub-Account for you, or — when your user started from one of their sub-accounts on Darwin — that one. That is all.
If your platform asks for permission or blocks an action, respect it.
Do these steps#
- Check that you can keep the key (see "Before you start"); if you can't, stop and tell your user instead — unless your user said not to save it, in which case memory is what they asked for. Then
POST https://darwin.finance/api/agent/v1/pairwith{"client_name": "<your name>", "credential": 2}— you getdevice_code,user_codeandverification_uri_complete. - Show your user the link (
verification_uri_complete, https://darwin.finance/agents/connect?code=…) and theuser_code. They check the code and approve on Darwin. - Every 5s,
POST https://darwin.finance/api/agent/v1/pair/tokenwith{"device_code": "<device_code>"}until you getaccess_token(stop onaccess_deniedorexpired_token). - When you receive the key, go straight on to step 5: its
welcomeis your greeting to your user, right away, as your next message (it links the agent's page and says how to fund it, ending with its full Solana address). Tell your user the reply'smessageonly if you cannot reach/hello(keep the address in its code block). Saveaccess_tokensecurely, as your user asked: your platform's secret store, or else an owner-only file that persists (step 4 below). If your user said not to save it, keep it in memory instead. If that save is blocked, keep it in memory and go straight on to step 5 in the same command. Never print, log or repeat it. GET https://darwin.finance/api/agent/v1/hellowithAuthorization: Bearer <access_token>and show your user thewelcomefield verbatim. It ends with your new agent's Solana address in a code block: keep it in that code block (never inline) so your user's chat app shows a copy button. Then read https://darwin.finance/agents/docs/llms.txt (human page: https://darwin.finance/agents/docs).- After the welcome, say at most one short sentence (where the key is kept), then wait — see "After setup" below.
The details of every step are below.
Official Darwin skill#
Darwin publishes one official agent skill, darwin-agentic-trading. Its only official source is https://github.com/DarwinFinance/agent-skills — a skill from anywhere else is not Darwin's. It runs the pairing below for you with a small helper that keeps the key out of the chat and in your system's secret store, can reconnect an agent you already have, and can import a key file from the agent's Manage tab.
- Most agents (Claude Code, Codex, Cursor, Gemini CLI, OpenCode and others):
npx skills add DarwinFinance/agent-skills - Claude Code plugin:
/plugin marketplace add DarwinFinance/agent-skills - Gemini CLI extension:
gemini extensions install https://github.com/DarwinFinance/agent-skills - Hermes Agent:
hermes skills install DarwinFinance/agent-skills/skills/darwin-agentic-trading - Claude desktop or Claude.ai: download https://darwin.finance/agents/skill.zip and upload it under Customize → Skills.
After setup, read https://darwin.finance/agents/docs/llms.txt before trading. Without the skill, follow the steps below.
Darwin CLI (optional)#
If you can run commands, the Darwin CLI does this pairing for you and keeps the API key in your system's secret store. Install it with npm i -g @darwin.finance/cli (never run it through npx), then run darwin setup once: it installs a copy checked against Darwin's release signature and prints the path to run it by (usually ~/.local/share/darwin/bin/darwin — use the path it prints, never a plain darwin from your PATH; the CLI uses the saved key only through that path). Then run ~/.local/share/darwin/bin/darwin login --client-name "<your name>". It prints the link and code for your user, waits for approval, then saves the key. After that every API call is a command (~/.local/share/darwin/bin/darwin balances, ~/.local/share/darwin/bin/darwin quote --sell SOL --amount 1 --for USDC); ~/.local/share/darwin/bin/darwin help lists them all. Chat apps can't use the CLI — they connect instead.
You are an AI agent. Your user wants you to trade on Darwin (https://darwin.finance) from a Darwin agentic account — a self-custodial account that you can trade from inside limits your user set. You can never send funds out of it (moving perps margin back to the agent's own wallet is allowed).
Follow these steps in order. Do not skip any. They take your user about a minute: you ask Darwin for a pairing code, your user approves it in their browser, and Darwin hands you an API key.
- Base URL:
https://darwin.finance - This document:
https://darwin.finance/agents/setup.md - Full API reference:
https://darwin.finance/agents/docs/llms.txt(Markdown; web page:https://darwin.finance/agents/docs)
Step 1 — Check that you can keep the key, then ask Darwin for a pairing code#
Before you send anything, decide where the key will live: your platform's secret store, or a file you are allowed to write that will still be there in a later session. Darwin shows the key only once, so a key you cannot keep is lost. If you can't keep it — your platform does not let you write credentials, or your workspace is temporary and gets reset — do not start pairing. Tell your user, in one or two sentences, that this app can't keep a Darwin key yet, and suggest running setup from an AI agent on their own computer (Claude Code, Codex, Hermes, or any agent with the Darwin skill: npx skills add DarwinFinance/agent-skills), or creating an API key on their agent's Manage tab and giving it to you for this session only, as a downloaded key file (never pasted into the chat; its key field is the API key). If your user is in a chat app such as Claude or ChatGPT, the easiest way is Darwin's connector, which needs no key: they add https://mcp.darwin.finance/mcp as a custom connector in that app's settings, sign in to Darwin when it asks, and choose what it can do: create a new Agentic Sub-Account for it, trade out of one or all of their existing ones, or read only. (If your user said not to save the key, holding it in memory for this session is what they asked for.)
Then ask for a pairing code:
POST https://darwin.finance/api/agent/v1/pair
Content-Type: application/json
{"client_name": "<your app or agent name, e.g. Claude Code>", "credential": 2}intent: if the address your user gave you for this file ends with ?intent=cit_…, add "intent": "cit_…" (that exact value) to this request. It tells Darwin which of your user's Agentic Sub-Accounts they started from; it does nothing on its own. Without it, your user's approval creates a new, empty Agentic Sub-Account for you.
"credential": 2 says you understand the second kind of key Darwin may answer with. Your user then chooses in their browser: a new, empty Agentic Sub-Account for you (as below), or one or all of the Agentic Sub-Accounts they already have. If the answer to this request includes "credential": 2, the key you finally receive may say "credential": "owner_key": it reads your user's whole Darwin account and trades only the sub-accounts named in its trade field ({"scope": "agent", "agent": "<id>"} or {"scope": "all_active"}). With an all_active key, send X-Darwin-Agent: <agent id> on every account call and start with GET /api/agent/v1/agents; follow its instructions. Neither kind can ever withdraw or move funds out.
Read-only. If your user asked for a read-only connection (the setup line says "read-only"), send "read_only": "only" together with "credential": 2. Your user is then offered only a read-only connection: an API key that reads Darwin market data and their whole account, and can never trade, move funds, or create or pair an Agentic Sub-Account. Continue only if the answer to this request says both "credential": 2 and "read_only": "only"; otherwise stop and tell your user that Darwin can't connect you read-only here (never retry without it). The key you finally receive must say "credential": "owner_key", "trade": {"scope": "none"} and "read_only": true — refuse to use anything else. Then GET /api/agent/v1/hello with no X-Darwin-Agent header returns the read-only welcome. Never offer to trade with it: Darwin refuses every trade from a read-only key. If you can hold a read-only key but your user did not ask for one, you may send "read_only": "allowed": your user may then choose read-only, or a trading connection.
client_name is optional, at most 60 characters, and shown to your user marked unverified. Use your real app or agent name. A name that claims to be Darwin is refused.
mode is optional too. Leave it out for a normal pairing, which connects you to a new, empty Agentic Sub-Account (or, with intent, the one your user started from). Send "mode": "reconnect" only when you lost the key to an agent your user already has (see step 4): your user then picks that agent in their browser and confirms with their second factor. The answer echoes mode; if you asked for reconnect and the answer does not say "mode": "reconnect", stop and tell your user — do not show them the code. Start ONE reconnect and poll it; if you must start another while it is still waiting, send "replaces": "<the previous device_code>" with it, so your user can't approve a code you no longer poll.
The answer:
{
"device_code": "darwinAI_pair_…",
"user_code": "BCDF-GHJK",
"verification_uri": "https://darwin.finance/agents/connect",
"verification_uri_complete": "https://darwin.finance/agents/connect?code=BCDF-GHJK",
"expires_in": 600,
"interval": 5
}device_codeis your secret while you wait. Keep it to yourself: do not show it to your user or put it in a URL.user_codeis for your user.- The code is good for 10 minutes.
Step 2 — Show your user the link and the code#
Tell your user, in your own words but with these exact values:
> Open verification_uri_complete and sign in to Darwin. > Check that the code on the page is user_code, then approve it.
Show both the link and the code. The code is how your user knows the request on that page is yours — Darwin asks them whether it matches what you showed. Darwin shows your user what this connects: a new, empty Agentic Sub-Account for you, or the one they started from on Darwin. Don't tell your user it will be a new one, and don't guess: the key you receive says what you trade.
If your turn ends when you reply (you cannot keep polling in the background), add one line to that message: once they approve, come back to this chat and say "Darwin start". Darwin cannot message you: you learn of the approval only by polling. On your user's next message, poll pair/token before anything else; with the key, go straight to Step 5 and greet them.
Step 3 — Poll until your user answers#
Every interval seconds (start with 5), send:
POST https://darwin.finance/api/agent/v1/pair/token
Content-Type: application/json
{"device_code": "<device_code from step 1>"}Until your user answers, Darwin replies HTTP 400 with a JSON error. That is normal — it is the protocol (RFC 8628), not a failure:
error | Meaning | What you do |
|---|---|---|
authorization_pending | Your user has not approved this pairing yet. Keep polling every interval seconds. | Wait interval seconds, poll again. |
slow_down | You are polling too fast. Wait at least interval seconds between polls. | Add 5 seconds to your interval, keep polling. |
expired_token | This pairing code has expired or was already used. Start again with POST /api/agent/v1/pair. | Go back to step 1 if your user still wants to connect. |
already_redeemed | This pairing already delivered your key. Stop polling. If you didn't keep it, do NOT start a new pairing (that creates a new agent): start one with "mode":"reconnect". | Stop polling. Never start a new pairing to recover the key: that creates a new agent. Use "mode": "reconnect" (step 4). |
access_denied | Your user declined this pairing, or the agent they chose can no longer take a key. Do not retry on your own; ask your user. | Stop. Tell your user. |
Keep polling until you get expired_token, already_redeemed, access_denied, or a key. Do not give up on your own clock: your user may be creating a new Agentic Sub-Account for you, so Darwin keeps the code alive longer than expires_in once they press Yes.
A 429 means too many requests from your network: wait a few minutes. A 503 means Darwin could not answer just then: wait a few seconds and poll again.
When your user approves, the next poll returns HTTP 200:
{
"access_token": "darwinAI_agent_…",
"token_type": "Bearer",
"agent": {
"name": "my-agent",
"solanaAddress": "<your new agent's Solana wallet address>",
"agentPageUrl": "https://darwin.finance/agent-account/…",
"manageUrl": "https://darwin.finance/agent-account/…/manage"
},
"key_name": "Paired: <your client_name>",
"message": "Connected to Darwin as `my-agent`. To fund it, use Transfer Funds on [its page on Darwin](…). Agents can't withdraw or transfer funds out of this account; only you can. Its Agentic Account was created successfully and I'm connected to it, ready to trade. …"
}When you receive the key, call /hello right away (step 5) and show your user its welcome as your very next message — even if they have not said anything since they approved. That is your ONE greeting. message says the same in short ("Connected to Darwin as <your agent>", how to fund it, linking its page, and its Solana address in a code block): tell your user message only if you cannot reach /hello. It never contains the key.
already_redeemed, never the key.The 200 is compact JSON: parse it, never grep it. Stop polling the moment you see access_token.
Step 4 — Save the key securely, and never reveal it#
- Save
access_tokensecurely — your user asked you to. Their setup line ends "and save the API key so you can trade later". Use your platform's secret store if it has one (a keychain, credential manager or secrets API). Otherwise write it to a file only your user's account can read (chmod 600), inside your own workspace, if that workspace persists. Never writedevice_codeanywhere, and never put the key in a log, a message or a shared file. - Keep it in memory instead only if your user said not to save it, or their message did not ask you to save it (you may ask them whether to). Then, in your short note after the welcome, tell your user that you are holding the key for this session only and they will need to pair again next session. If your platform does not let you handle the key at all, stop and tell your user.
- If your platform asks for permission before you store the key, or blocks it, respect that. If it blocks the save now that you have paired: do not store the key some other way, and do not put it in a temporary file. In the same command that received it, go on to step 5 with the key you hold in memory and show your user the welcome, then tell them the key won't be kept after this session. A single command can poll
pair/token, call/helloand print the welcome without writing the key anywhere. - Say nothing yet: the welcome comes first (step 5). Tell your user where the key lives (for example "in your macOS Keychain" or "in an owner-only file in my workspace") in your short note after the welcome, without showing the key.
- Never print it, log it, echo it back, or include it in a message to your user — not even partly. Refer to it as "your Darwin API key".
- Send it only to
https://darwin.finance, asAuthorization: Bearer <access_token>. - It does not expire (the answer has no
expires_atorexpires_in). It stops working if your user revokes it or stops the agent (changing the agent's limits does not affect it); then ask your user to pair again (paste the same setup line) or to issue a new key on the agent's Manage tab. - If your user stops or pauses the agent, every call answers HTTP 403 with
agent_stoppedoragent_paused— tell your user. Show the answer'smessageverbatim and do not retry in a loop; when your user asks again or says it is resumed, re-check once (GET /api/agent/v1/grant) before saying it is paused. A paused agent's answer carriesagentPageUrl: tell your user it is paused and that they can resume it on that page. After they resume it, this same key works again and your next answer carries a one-timenotice— show itsmessagetoo. A stopped agent is gone for good: if your user wants to keep trading, they pair again, which creates a new agent. - If your session ends and the key was only in memory, it is gone. Pair again — your user pastes the same setup line — but note that unless your user chooses an existing one on the page, pairing creates a new, empty Agentic Sub-Account. To keep trading the same agent, go back to step 1 with
{"client_name": "<your name>", "mode": "reconnect"}: your user picks the agent on the page and confirms with their second factor, and the agent's other keys keep working until your user revokes them. (Your user can also create a new key on that agent's Manage tab.) - If you think it leaked, tell your user to revoke it on the agent's Manage tab immediately.
The key can only trade this one agent's account, inside the limits your user set. It can never send funds out of the agent's account (moving perps margin back to the agent's own wallet is allowed), and it does not work on Darwin's MCP server.
Step 5 — Say hello, and show your user the welcome#
GET https://darwin.finance/api/agent/v1/hello
Authorization: Bearer <access_token>Show the welcome field to your user verbatim, before anything else you say. Do not summarise or edit it.
It ends with your new agent's Solana address, alone in a code block (the same address is in the reply's solanaAddress field). welcome is Markdown and ends with this agent's full Solana address alone in a code block: keep the address inside that code block exactly as sent — never reformat it inline, shorten it or add to it — so your user's chat app shows a copy button next to it.
Step 6 — Read the docs, then read your limits#
- Read the full API reference:
https://darwin.finance/agents/docs/llms.txt(Markdown; the same content as a web page ishttps://darwin.finance/agents/docs). It is long; read it before your first order. Example prompts to share with your user:https://darwin.finance/agents/examples. - Call
GET https://darwin.finance/api/agent/v1/grantwith your key. It tells you what this agent may trade, its per-trade and per-day limits, and how much of today's budget is left. - Before trading a US stock or ETF, call
GET https://darwin.finance/api/agent/v1/market-status/us-equities(public, no key needed). Tokenized stocks trade 24/7 and Darwin accepts agent stock orders at any hour, but liquidity is substantially reduced when the US market is closed — stock quotes and orders then carrymarketSession: "closed"and awarning.
Keep what you read to yourself unless your user asks — see "After setup".
If your owner gives you a key file#
Your owner can create your API key themselves — on the agent's Manage tab, or by setting up an agent manually — and download it as a key file. If they attach one in the chat or tell you where it is, you do not need to pair.
If you have the official Darwin skill, import the file with it: darwin.py import --keep-file <file>. The skill checks the key with Darwin (for a read-only file, that the key trades nothing), stores it, and from then on adds it to your calls. The skill reads no other file. If it says it stored the key in memory only, keep the file somewhere that will still be there in a later session, and import it again when the skill says the key is gone. When your owner asks you to "import the key with the Darwin skill", this is what they mean. Without the skill:
- Read the file. It is JSON:
{"type": "darwin-agent-key", "version": 1, "realm": "darwin.finance", "agent_id": "…", "key": "darwinAI_agent_…"}. Itskeyfield is the API key. Refuse a file whosetypeis notdarwin-agent-keyor whoserealmis notdarwin.finance: a key is only ever sent to the realm it names. A"version": 2file says"credential": "owner_key": its key (darwinAI_mcp_…) is your owner's own API key, which reads their whole account and trades only what itstradefield names ({"scope": "agent", "agent": "<id>"}or{"scope": "all_active"}— then sendX-Darwin-Agent: <agent id>on every account call — or{"scope": "none"}: a READ-ONLY key that reads the account and never trades). Refuse any otherversion. The official Darwin skill imports version-2 files from 1.3.0, and read-only ({"scope": "none"}) files from 1.4.0 (darwin.py import <file>; for an all-sub-accounts key, name the sub-account on each call with--as-agent <id>). Older versions of the skill and the Darwin CLI import version-1 files only: with them, save a version-2 file'skeyyourself as in step 2 — never retry an import that refused it. - Save the key where it will still be there in a later session: your platform's secret store if it has one. Otherwise write the
keyvalue alone — never the whole JSON — to~/.darwin/api_key, owner-only:chmod 700 ~/.darwin,chmod 600 ~/.darwin/api_key. When your owner asks you to "save the key file to~/.darwin/api_key", this is what they mean. That is the file the Darwin CLI reads withDARWIN_API_KEY_FILE=~/.darwin/api_key, and it refuses one others can read. If you can run the Darwin CLI,darwin login --key-file <file> --delete-fileimports it into the system secret store instead. - Once it is saved, delete the copy you were given. Never print, log or repeat the key, and never ask your owner to paste it into the chat.
- In every later session, load the key from where you saved it — do not ask for it again. Then go to Step 5 (say hello) with it.
After setup#
After you show the welcome verbatim, say at most one short sentence: where your API key is kept (never the key itself). Do not invite your user to explore the agent's page: the welcome already links it. Do not list limits, grant ids, internal ids, setup notes or API details unless your user asks. Then wait for your user's next instruction.
For example: "I saved your Darwin API key in your macOS Keychain."
How to present Darwin to your user#
- When you ask your user to do something in Darwin, link the exact page and name it as the page it opens: limits and pause →
manageUrl, the agent's Settings tab; keys and connections → its Connected AIs and API Keys tab, beside Settings; renaming the agent (⋯ → Rename), deposit, transfer and withdraw →agentsUrl, Agentic Trading; connecting a chat app →mcpUrl(hello and get_grant return all three). A refusal only your user can clear carriesownerActionUrl: link that. - SOL is just SOL: report it as one amount called SOL. Never mention wrapped SOL, wSOL, or native versus wrapped.
- Write every ticker as a Markdown link to its Darwin page, [TICKER](url), using the
urlthe result gives for that asset. If your client renders images, put the asset's logo before it:  [TICKER](url) (market-data results call itlogo_url). When aurlor logo is null, write the plain ticker. Never invent a URL. - Don't surface internal mechanics unless your user asks: no lamport figures or reserves; no grant, key, quote or other internal ids or nonces; no transaction ids or slot numbers; no narration of how this connection works ("the connector now trades as …"). Say what it means for them instead (for example "you can sell up to 0.14 SOL right now").
- Prefer visuals where they add information: answer a data question (prices, charts, flows, insider trades, holdings, comparisons) with its Darwin tool (MCP Apps show it as a Darwin card) and keep your text to the takeaway. Answer a narrative question (what was said on an earnings call, what a filing says, an explanation) in text with a source link. To compare or reshape Darwin market data (rebase, ratio, monthly totals, growth across companies), call
visualize; never put Darwin data in itscomputed. Chart growth over time, not a card per company. Where cards don't show, use a Markdown table with linked tickers, not prose.