Skip to content

docs(0358): pay per request in the agent skill - #442

Merged
adamkoot merged 9 commits into
developfrom
docs/0358_pay-per-request-in-the-agent-skill
Dec 3, 2026
Merged

adamkoot merged 9 commits into
developfrom
docs/0358_pay-per-request-in-the-agent-skill

Conversation

@adamkoot

@adamkoot adamkoot commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • skills/stellar-prices-api/SKILL.md gets a second path beside the free key: pay per request through the /x402/v1/ twins from 0356, as a testnet preview (XLM and USDC, ohlcv 1h/24h, batch ≤ 5). With the stellar-x402 MCP tools when the agent has them (as in the Claude Desktop run, stellar-x402 0042), else a short script on the upstream @x402/fetch 2.x, capped at $0.01 a payment.
  • The key steps follow the shared sign-in: signing in issues no key, the dashboard's Prices API tab offers Get API Key (no more "first sign-in issues the key", Generate API Key, Get my API key). Docs link → /api/docs/prices.
  • docs/prices-api-general-overview.md §4/§7: the key is required on /v1, not on the paid twins.
  • Checked on testnet 2026-12-01: the script's blocks cut out of SKILL.md and run unchanged (3 settlements), and fresh claude -p --model sonnet agents with only the skill bought XLM's price, one through the MCP tools and one through the script. Hashes in the task file.
  • skills.stellar.org copies this file raw from master, so agents get it with the next release; the card's description changes in a separate PR to stellar/stellar-dev-skill.

Access flow (akot, 2026-12-02)

With no key the skill no longer stops at "get a key":

  • Step 1 checks STELLAR_PRICES_API_KEY (environment, then .env). With a key: /v1, nothing else offered. Without one, the agent offers the ways in that fit the request, each with its cost, and waits for the choice: the stellar-x402 connector (first when call_paid_http is among its tools), a free key through Discord (walked through step by step), setting the connector up, or the script. A request outside the testnet sandbox gets only the key, with the reason.
  • Ask before paying: before the first payment the agent states what the task costs (each request, and the total when there is more than one) and waits for a yes.
  • Connector setup: summarized and linked to stellar-x402's apps/mcp-local/README.md#claude-desktop; it clones develop, since main has no search_resources or listing yet.
  • Secrets in .env: both the API key and the script's STELLAR_SECRET_KEY. An export in another terminal never reaches the agent.
  • Errors table: a 502 or 504 on /x402/v1 after the payment was sent may still settle, so check the payer's last transaction before paying again.

Verified 2026-12-02 with fresh claude -p --model sonnet agents, each transcript checked by a script. Before the change, an agent with no key and no connector never mentioned the connector. After it:

  • P1, no key, no connector → key, connector setup and script offered; nothing paid.
  • P2, connector → asked at 0.001, then one call_paid_http, 8814c5c6…f43e.
  • P4, AQUA → key only.
  • P5/P6, payer secret in .env → asked before paying.
  • By hand in Claude Code: a key in .env → /v1 at once, no menu.

The script blocks are byte-identical to 2026-12-01's, and their testnet run passed again. Details in the task file.

Three routes have keyless /x402/v1 twins since 0356. The skill offers them
beside the free key: the stellar-x402 MCP tools when the agent has them,
else a short script on the upstream @x402/fetch, capped at one cent a
payment. Testnet preview: XLM and USDC only.

The key steps follow the shared sign-in: signing in issues no key, the
Prices API tab's Get API Key does.
The skill told the agent to ask for the payer's secret key, which puts it
in the transcript; the user now sets it in the MCP server's config or in
STELLAR_SECRET_KEY. After the payment was sent, a 402 with a
PAYMENT-RESPONSE, a 502 or a 504 may still settle (the crate's
settlement_failed and its /settle timeout), so the skill no longer says
nothing is charged until the answer is below 400. The facilitator link
pointed at a host whose root answers 404, and the overview's revision
history gets its row for the /x402/v1 twins.
The errors table told an agent to retry every 500, 502 and 504. On the paid
routes a 502 or 504 can come after the payment was sent, and the transfer may
still land, as the pay-per-request section already says: check the payer's
last transaction before paying again.
Without a key the skill told the agent to stop and ask for one, and it
paid with the connector as soon as it had the tools. akot's access flow
(2026-12-02): the agent offers the ways in that fit the request, each
with its cost, and waits: the stellar-x402 connector (first when its
tools are there), a free key through Discord, setting the connector up,
or the script. Outside the testnet sandbox only the key is offered. No
payment before the user has heard the price and said yes. The
connector's setup is summarized and linked to the stellar-x402 README.
The script blocks are unchanged.
The connector's setup cloned the default branch, which has neither
search_resources nor the listing guard: it now clones develop. The pay
sections act only on the user's choice and yes, and the quote before the
first payment covers the whole task. Step 1 states what every paid way
in costs and the sandbox's candles exactly, and recommends .env, since
an export in another terminal does not reach the agent. The task's
evidence now holds the final run, with P6 (the user says the payer key
is in .env).
An agent told the user to export STELLAR_SECRET_KEY, as the script
section said. An export in another terminal never reaches the agent, so
the script would stop with "STELLAR_SECRET_KEY is not set". The section
now asks for the project's .env and says why, as Step 1 already does
for the API key. Found in akot's manual run with a connector that has
no payer.

@stkrolikiewicz stkrolikiewicz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me; one small precision nit below, non-blocking.

Comment thread skills/stellar-prices-api/SKILL.md Outdated
| ----------- | ----------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 400 | `{"code": "invalid_id" \| "invalid_query" \| "invalid_body", "message": ...}` | `message` names the bad parameter. Fix it; do not retry as-is. |
| 403 | `{"message": "Forbidden"}` | Missing, wrong or disabled key. Check the key is set and sent as `x-api-key`. Do not suggest Regenerate. No 401 in production. |
| 402 | Terms in the `PAYMENT-REQUIRED` header | Only on `/x402/v1`: the request's price. An x402 client pays it and retries. One after a payment may still settle. |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: "One after a payment may still settle" drops the condition. In stellar-x402's axum layer a /verify refusal is a 402 with {"error": ...} and no PAYMENT-RESPONSE, and it never settles; only settlement_failed (after /settle) carries PAYMENT-RESPONSE. The Pay per request section says it right. Maybe: "One that carries a PAYMENT-RESPONSE may still settle; without one it was refused: read its error." (as SorobanScan's skill words it).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 977cdd3 with that wording. I checked it against the layer at the rev Prices pins (ff5933c2): a refused /verify is a 402 with {"error"} and no PAYMENT-RESPONSE; only settlement_failed carries one.

Only a 402 that carries a PAYMENT-RESPONSE (a failed settlement) may
still settle; one without it is a refused verification with an error.
From stkrolikiewicz's review of #442.
@adamkoot
adamkoot merged commit e512747 into develop Dec 3, 2026
4 checks passed
adamkoot added a commit that referenced this pull request Dec 3, 2026
Merged as #442 (e512747) after stkrolikiewicz's review, released by
#444 as prod-2026-12-03 (d817982): the raw URL serves the new skill.
The card's description is a PR to stellar/stellar-dev-skill.
@adamkoot
adamkoot deleted the docs/0358_pay-per-request-in-the-agent-skill branch December 3, 2026 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants