feat(apikey): a BlockRun API key works everywhere a wallet key does - #59
Merged
Conversation
Every paid path assumed x402 — a 402 challenge, a local signature, a retry — which made holding a wallet the price of admission. A key from user.blockrun.ai now works in the same place, across all fourteen client classes, with no new client type and no signature change: the private_key parameter accepts a brk_ key, and BLOCKRUN_API_KEY is read when it is empty. Four things beyond the header, each a silent failure rather than an import error: - api.blockrun.ai serves /v1 at the root and answers /api/v1 with wrong_host, so the account rail needs its own base URL. - poll_url is minted relative to the x402 gateway's host, so it arrives as /api/v1/... — resolved unchanged, every async job polls a 404 to timeout. - The async submit answers 202 on the FIRST post here. ImageClient raised "API error: 202" and VideoClient raised "Expected 402 on first POST", so both were broken for keys before they began. - setup_agent_wallet() minted a keyfile unconditionally. With a key configured there is nothing to sign with, so it writes nothing. SolanaLLMClient and AsyncSolanaLLMClient take the key too, and no longer need the optional x402 SDK when one is present: on the account rail there is no transfer to sign, so the chain stops being a question. blockrun_llm.apikey holds the rail in one module — precedence, auth_headers, poll-URL resolution, the two refusals — rather than fourteen copies that drift. Each client's httpx.Client carries the key as a default header, so the sixteen request sites did not have to be edited one by one. Wallet users are untouched: precedence is explicit argument, then BLOCKRUN_API_KEY, then the wallet variables. BLOCKRUN_API_KEY_URL is deliberately separate from BLOCKRUN_API_URL — the latter names an x402 gateway, and following it would send the key to a host configured for another rail. Wallet-only helpers refuse rather than answer wrongly. get_balance() returning 0 is indistinguishable from an empty wallet, and an agent gating on it would stop calling a funded account. tests/conftest.py clears BLOCKRUN_API_KEY for every test: without it, the "no credential" tests fail on the machine of anyone who has a key exported. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01T5RKUETYjxwNRqkURLnatJ
This was referenced Sep 5, 2026
VickyXAI
pushed a commit
that referenced
this pull request
Sep 5, 2026
`--check` was green because it only validates the keys a marker actually renders, and those five were current. The rest of the snapshot had drifted: withFallback 48 → 34, withFallbackAllEntries 89 → 73, aliases 229 → 259, plus three mcp context keys the artifact now carries. No rendered number changes, so this is not a docs fix — it stops the next marker added for one of those keys from rendering a stale value on day one. Produced by `scripts/sync-brand-numbers.mjs --refresh`, no hand-edited digits. Supersedes #51, which proposed the same refresh against a 26 Aug main. Its five rendered numbers have since landed independently, so the branch had nothing left to deliver and conflicted with the API-key documentation merged in #59/#60. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QMLNFbR6Jg2HBFpRUGBjyh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The SDK accepts a
brk_live_…key from user.blockrun.ai anywhere it accepts a wallet private key. Requests go toapi.blockrun.ai, authenticate withAuthorization: Bearer …, and draw prepaid credit instead of signing an on-chain payment.No new client type and no new constructor. The
private_keyparameter that all fourteen client classes already take now recognises abrk_prefix, andBLOCKRUN_API_KEYis read when it is empty — so every existing skill and script gains the rail without a code change.blockrun_llm/apikey.pyholds the rail in one module: precedence,auth_headers, poll-URL resolution, and the two refusals. Each client'shttpx.Clientcarries the key as a default header, which is why sixteen request sites did not have to be edited one by one.Why it needed more than a header
Each of these fails silently rather than at import time:
api.blockrun.aiserves/v1/…at the root and answers/api/v1/…withwrong_hostpoll_urlis minted relative to the x402 gateway's host, so it arrives as/api/v1/…ImageClientraisedAPI error: 202,VideoClientraised "Expected 402 on first POST" — both broken for keys before they startedsetup_agent_wallet()minted a keyfile unconditionallySolanaLLMClient/AsyncSolanaLLMClienttake the key too, and no longer require the optional x402 SDK when one is present: on the account rail there is no transfer to sign.Wallet users
Unaffected, and verified live after the change:
Precedence: an explicit argument, then
BLOCKRUN_API_KEY, then the wallet variables. Nothing changes until that variable is set, and passing a wallet key explicitly always opts back out.client.payment_modemakes the choice inspectable.BLOCKRUN_API_KEY_URLis deliberately notBLOCKRUN_API_URL— the latter names an x402 gateway, and an API-key client following it would send the key to a host configured for a different rail.Wallet-only helpers
get_balance(),get_balance_testnet()andonramp()raise aValueErrornaming the helper and pointing at the dashboard. Returning0would be the worst available answer: indistinguishable from an empty wallet, and an agent gating on it would stop calling a well-funded account.get_wallet_address()returns"". A 402 on this rail is a credit refusal, not a challenge, so it raises aPaymentErrorquoting the gateway's reason and the top-up page.Every client also raised its own "nothing configured" wording listing only wallet routes, which stopped being the whole truth the moment a key became a credential.
missing_credential_error()lists both — the two tests asserting the old wording are updated.Tests
30 new tests in
tests/unit/test_apikey.py; 699 passed, 15 skipped, ruff and black clean.tests/conftest.pyclearsBLOCKRUN_API_KEYfor every test. Without it, every "no credential configured" test fails on the machine of anyone who actually has a key exported — which is everyone working on this.Verified live against the real gateway with a real key: chat (paid + free),
list_models,list_image_models, Grok Live Search, Exa, RPC, and the wallet-only refusals.README
Opened with "No API keys required", which is no longer true. Now leads with the two rails, adds the API-key path to Quick Start and a full Option A section (signup, key minting, top-up — min $5, with the 5.5% + $0.30 fee charged once at purchase rather than per call — precedence, and what changes). Solana now leads where the two chains are named: sub-second settlement with the facilitator paying the fee makes it the better default; Base is unchanged and still what the bare
LLMClientuses. The environment table listed two variables and omittedSOLANA_WALLET_KEYentirely; it now lists nine.🤖 Generated with Claude Code
https://claude.ai/code/session_01T5RKUETYjxwNRqkURLnatJ