From f8c2aa27b39b4aff4478aa5c45751ea443e4cab6 Mon Sep 17 00:00:00 2001 From: 1bcMax Date: Sat, 28 Nov 2026 12:58:04 -0600 Subject: [PATCH] chore: retire the testnet; release 1.24.2 testnet.blockrun.ai (Base Sepolia, chain 84532) was retired on 2026-10-02 and no longer resolves. The SDK stops offering it without breaking imports: - testnet_client() / async_testnet_client() stay importable (and in __all__) but raise RetiredEndpointError naming the date and the mainnet replacement, LLMClient() / AsyncLLMClient(). async_testnet_client() is a plain function now, so it raises at the call, awaited or not. - validate_api_url() refuses the testnet.blockrun.ai host with the same error, so an explicit api_url, BLOCKRUN_API_URL, or any other client pointed at it fails at construction rather than with a DNS error. - TESTNET_API_URL kept as a deprecated class attribute; is_testnet() kept and always False; get_balance() and the 402 network default are Base mainnet only. Base Sepolia stays in the x402 chain table for third-party 402s. - README: testnet sections replaced by a short "Testnet (retired)" note; llama-index integration's api_url example is now Circle Arc. - tests/unit/test_retired_testnet.py pins the behavior (23 tests). - Release 1.24.2: VERSION, pyproject.toml, __version__, CHANGELOG. --- CHANGELOG.md | 32 ++++ CLAUDE.md | 3 +- README.md | 58 ++---- VERSION | 2 +- blockrun_llm/__init__.py | 4 +- blockrun_llm/billing.py | 5 +- blockrun_llm/client.py | 165 +++++++----------- blockrun_llm/validation.py | 45 +++++ blockrun_llm/x402.py | 6 +- examples/sweep_all_chat_models.py | 4 - .../llama-index-llms-blockrun/README.md | 2 +- .../llama_index/llms/blockrun/base.py | 4 +- .../tests/test_llms_blockrun.py | 4 +- pyproject.toml | 2 +- tests/unit/test_retired_testnet.py | 150 ++++++++++++++++ 15 files changed, 325 insertions(+), 161 deletions(-) create mode 100644 tests/unit/test_retired_testnet.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 8422884..9c06471 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,38 @@ All notable changes to blockrun-llm will be documented in this file. ## Unreleased +## 1.24.2 — 2026-11-28 + +### Removed +- **The BlockRun testnet is gone.** `testnet.blockrun.ai` (Base Sepolia, + chain 84532) was retired on 2026-10-02 and no longer resolves, so the SDK + stops offering it. Nothing is removed from the import surface: + - `testnet_client()` and `async_testnet_client()` stay importable and in + `__all__`, but calling them raises `RetiredEndpointError` naming the + retirement date and the replacement, `LLMClient()` / `AsyncLLMClient()` + on Base mainnet. `async_testnet_client()` is now a plain function, so it + raises at the call whether or not the result is awaited. + - `validate_api_url()` refuses the `testnet.blockrun.ai` host with the same + error, so `LLMClient(api_url="https://testnet.blockrun.ai/api")`, + `BLOCKRUN_API_URL` set to it, and every other client fail at construction + instead of with a DNS error on the first request. + - `LLMClient.TESTNET_API_URL` / `AsyncLLMClient.TESTNET_API_URL` are kept as + deprecated attributes; `is_testnet()` is kept and always returns `False`. + `get_balance()` always reads Base mainnet, and a 402 without a `network` + defaults to `eip155:8453`. + - Base Sepolia stays in the x402 chain table (`EVM_NETWORKS`), so the signer + can still pay a 402 from any other server that names it. + - For development without spending USDC, use the free models + (`routing_profile="free"`): they settle $0, so an unfunded wallet works. + +### Docs +- README: the "Testnet Usage" section, the testnet model table and the Base + Testnet row of the chains table are replaced by a short "Testnet (retired)" + note with the one-line migration. The API-key section no longer mentions a + `get_balance_testnet()` helper the SDK never had. +- llama-index-llms-blockrun: the `api_url` example is now Circle Arc + (`https://arc.blockrun.ai/api`) instead of the retired testnet. + ## 1.24.1 — 2026-11-27 ### Changed diff --git a/CLAUDE.md b/CLAUDE.md index 79687a1..ea65345 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -54,9 +54,10 @@ blockrun_llm/ - Base Mainnet (primary) — USDC - Arc (Circle, chain 5042) — USDC, via `api_url="https://arc.blockrun.ai/api"`; same `LLMClient` and key -- Base Sepolia (testnet) — Testnet USDC - Solana Mainnet — USDC SPL +The Base Sepolia testnet (testnet.blockrun.ai) was retired on 2026-10-02. `testnet_client()` / `async_testnet_client()` stay importable but raise `RetiredEndpointError`, and `validate_api_url` refuses that host. + The EVM domain signed follows the 402's `network` through `EVM_NETWORKS` in `blockrun_llm/x402.py`; a 402's `extra` is never trusted for it, an unknown network and a non-USDC `asset` are refused. ## Conventions diff --git a/README.md b/README.md index eeccd59..8bdcce2 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,6 @@ | **Solana** | Solana Mainnet | USDC (SPL), gasless — the facilitator pays the fee | ✅ Recommended for x402 | | **Base** | Base Mainnet (Chain ID: 8453) | USDC | ✅ | | **Arc** | Circle Arc (Chain ID: 5042) — `arc.blockrun.ai` | USDC (Arc's native token), settled by Circle — no gas per call | ✅ | -| **Base Testnet** | Base Sepolia (Chain ID: 84532) | Testnet USDC | ✅ Development | **Protocol:** x402 v2 on the wallet rails; plain bearer auth on the API-key rail. @@ -381,7 +380,7 @@ overrides the account-rail host; it is deliberately not `BLOCKRUN_API_URL`, which names an x402 gateway — an API-key client following that would send your key to a host configured for a different rail. -**What changes.** `get_balance()`, `get_balance_testnet()` and `onramp()` raise +**What changes.** `get_balance()` and `onramp()` raise a `ValueError` pointing at the dashboard rather than answering: returning `0` is indistinguishable from an empty wallet, and an agent gating on it would stop calling a well-funded account. `get_wallet_address()` returns `""`. Running out @@ -456,7 +455,7 @@ fixed quote. With `"auto"`, the gateway lists `exact` first; upto is taken only when all of these hold: - the 402 offers an EVM `upto` requirement with `extra.facilitatorAddress`, for - USDC on a network the SDK signs on (Base, Base Sepolia); + USDC on Base; - your wallet holds at least the ceiling in USDC; - Permit2 can already pull the ceiling from your wallet, **or** the gateway declares the `eip2612GasSponsoring` extension. In that case the SDK also signs @@ -713,16 +712,6 @@ The 8 free models are listed unde [Try It Free](#try-it-free-no-balance-required). Pin them by full model id, or use `routing_profile="free"`. -### Testnet Models (Base Sepolia) -Live per-model prices: [blockrun.ai/pricing](https://blockrun.ai/pricing) (agents: `GET https://blockrun.ai/api/v1/models`). Prices are not copied here, so this page never goes stale on a reprice. - -| Model | -| ------- | -| `openai/gpt-oss-20b` | -| `openai/gpt-oss-120b` | - -*Testnet models use flat pricing (no token counting) for simplicity.* - ### Verifying Models End-to-End The SDK ships two runnable sweep scripts under `examples/`: @@ -1612,46 +1601,23 @@ for model in models: print(f"{model['id']}: ${model['inputPrice']}/M input, ${model['outputPrice']}/M output") ``` -## Testnet Usage - -For development and testing without real USDC, use the testnet: - -```python -from blockrun_llm import testnet_client - -# Create testnet client (uses Base Sepolia) -client = testnet_client() # Uses BLOCKRUN_WALLET_KEY - -# Chat with testnet model -response = client.chat("openai/gpt-oss-20b", "Hello!") -print(response) - -# Check testnet USDC balance -balance = client.get_balance() -print(f"Testnet USDC: ${balance:.4f}") -``` - -### Testnet Setup +## Testnet (retired) -1. Get testnet ETH from [Alchemy Base Sepolia Faucet](https://www.alchemy.com/faucets/base-sepolia) -2. Get testnet USDC from [Circle USDC Faucet](https://faucet.circle.com/) -3. Set your wallet key: `export BLOCKRUN_WALLET_KEY=0x...` - -### Available Testnet Models - -- `openai/gpt-oss-20b` (flat price per request) -- `openai/gpt-oss-120b` (flat price per request) - -### Manual Testnet Configuration +BlockRun's testnet (`testnet.blockrun.ai`, Base Sepolia) was retired on +2026-10-02. `testnet_client()` and `async_testnet_client()` are still +importable but raise `RetiredEndpointError`, as does any client pointed at +`https://testnet.blockrun.ai/api`. Use the mainnet client instead: ```python from blockrun_llm import LLMClient -# Or configure manually -client = LLMClient(api_url="https://testnet.blockrun.ai/api") -response = client.chat("openai/gpt-oss-20b", "Hello!") +client = LLMClient() # was: testnet_client() ``` +To develop without spending USDC, use the free models under +[Try It Free](#try-it-free-no-balance-required): they settle $0, so an +unfunded wallet works. + ## Billing & Cost Tracking Every paid call appends one line to `~/.blockrun/cost_log.jsonl` capturing diff --git a/VERSION b/VERSION index f9e8384..e4a973f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.24.1 +1.24.2 diff --git a/blockrun_llm/__init__.py b/blockrun_llm/__init__.py index a931c9b..62b4435 100644 --- a/blockrun_llm/__init__.py +++ b/blockrun_llm/__init__.py @@ -200,7 +200,7 @@ create_wallet as generate_wallet, # User-friendly alias ) -__version__ = "1.24.1" +__version__ = "1.24.2" __all__ = [ "DECISIONS_DEFAULT_MODEL", "DEFAULT_API_KEY_URL", @@ -336,6 +336,6 @@ # Entry point for agents (auto-creates wallet) "setup_agent_wallet", "status", - # Testnet convenience functions + # Retired testnet helpers: importable, raise RetiredEndpointError when called "testnet_client", ] diff --git a/blockrun_llm/billing.py b/blockrun_llm/billing.py index d5dfb56..5069dcf 100644 --- a/blockrun_llm/billing.py +++ b/blockrun_llm/billing.py @@ -138,7 +138,10 @@ def _add_filter_args(p: argparse.ArgumentParser) -> None: "--network", type=str, default=None, - help="filter to one network (base-mainnet / base-sepolia / solana-mainnet)", + help=( + "filter to one network (base-mainnet / solana-mainnet; base-sepolia on " + "records from the testnet, retired 2026-10-02)" + ), ) diff --git a/blockrun_llm/client.py b/blockrun_llm/client.py index f07de02..3b573ab 100644 --- a/blockrun_llm/client.py +++ b/blockrun_llm/client.py @@ -106,6 +106,7 @@ is_payment_replay, resolve_spend_limit, sanitize_error_response, + testnet_retired_message, validate_api_url, validate_eth_address, validate_max_tokens, @@ -700,7 +701,7 @@ def _exact_chat_payment( recipient=details["recipient"], amount=details["amount"], scheme=details.get("scheme"), - network=details.get("network", "eip155:84532" if client.is_testnet() else "eip155:8453"), + network=details.get("network", "eip155:8453"), resource_url=validate_resource_url( resource.get("url", f"{client.api_url}/v1/chat/completions"), client.api_url ), @@ -747,15 +748,15 @@ def _booked_cost( def _detect_network(api_url: str) -> str: """Map an API URL to the canonical network label used in billing - records. Returns ``base-mainnet`` / ``base-sepolia`` / ``solana-mainnet`` - / ``unknown``. + records. Returns ``base-mainnet`` / ``solana-mainnet`` / ``unknown``. + + Records written before 1.24.2 can also carry ``base-sepolia``, from the + testnet that was retired on 2026-10-02; no client can reach it now. """ if not api_url: return "unknown" if "sol.blockrun" in api_url: return "solana-mainnet" - if "testnet" in api_url: - return "base-sepolia" if "blockrun.ai" in api_url: return "base-mainnet" return "unknown" @@ -776,23 +777,19 @@ class LLMClient: Security: Your private key is used ONLY for local EIP-712 signing. The key NEVER leaves your machine - only signatures are transmitted. - Networks: + Network: - Mainnet: https://blockrun.ai/api (Base, Chain ID 8453) - - Testnet: https://testnet.blockrun.ai/api (Base Sepolia, Chain ID 84532) - - Testnet Usage: - For development and testing without real USDC: - - client = LLMClient(api_url="https://testnet.blockrun.ai/api") - # Or use the testnet convenience method - from blockrun_llm import testnet_client - client = testnet_client() - - Note: Testnet has limited models (openai/gpt-oss-20b, openai/gpt-oss-120b) + BlockRun's testnet (testnet.blockrun.ai, Base Sepolia) was retired on + 2026-10-02. To develop without spending USDC, call a free model (for + example ``smart_chat(prompt, routing_profile="free")``): it settles $0, + so an unfunded wallet works. """ DEFAULT_API_URL = "https://blockrun.ai/api" + # Deprecated: the testnet was retired on 2026-10-02. Kept so attribute + # access does not break on upgrade; constructing a client with it raises + # RetiredEndpointError. TESTNET_API_URL = "https://testnet.blockrun.ai/api" DEFAULT_MAX_TOKENS = 1024 @@ -2149,7 +2146,7 @@ def _handle_payment_and_retry_raw( recipient=details["recipient"], amount=details["amount"], scheme=details.get("scheme"), - network=details.get("network", "eip155:84532" if self.is_testnet() else "eip155:8453"), + network=details.get("network", "eip155:8453"), resource_url=validate_resource_url(resource.get("url", url), self.api_url), resource_description=resource.get("description", "BlockRun AI API call"), max_timeout_seconds=details.get("maxTimeoutSeconds", 300), @@ -2307,7 +2304,7 @@ def _handle_get_payment_and_retry( recipient=details["recipient"], amount=details["amount"], scheme=details.get("scheme"), - network=details.get("network", "eip155:84532" if self.is_testnet() else "eip155:8453"), + network=details.get("network", "eip155:8453"), resource_url=validate_resource_url(resource.get("url", url), self.api_url), resource_description=resource.get("description", "BlockRun AI API call"), max_timeout_seconds=details.get("maxTimeoutSeconds", 300), @@ -3016,8 +3013,12 @@ def get_wallet_address(self) -> str: return self.account.address def is_testnet(self) -> bool: - """Check if client is configured for testnet.""" - return "testnet.blockrun.ai" in self.api_url + """Deprecated: always ``False``. + + BlockRun's testnet was retired on 2026-10-02 and a client can no longer + be constructed against it. Kept so existing callers do not break. + """ + return False def _billing_meta(self) -> dict[str, str | None]: """Return billing metadata (wallet / network / client_kind) for the @@ -3072,11 +3073,7 @@ def get_balance(self) -> float: if self.api_key: raise wallet_only("get_balance") """ - Get USDC balance on Base network. - - Automatically detects mainnet vs testnet based on API URL: - - Mainnet: Base (Chain ID 8453) - - Testnet: Base Sepolia (Chain ID 84532) + Get USDC balance on Base mainnet (Chain ID 8453). Returns: float: USDC balance (6 decimal places normalized) @@ -3085,12 +3082,9 @@ def get_balance(self) -> float: balance = client.get_balance() print(f"Balance: ${balance:.2f} USDC") """ - # USDC contracts - # Mainnet: Base - # Testnet: Base Sepolia - # Contract + public RPCs from the shared chain table (x402.EVM_NETWORKS), - # which the upto scheme's allowance reads use too. - net = EVM_NETWORKS["eip155:84532" if self.is_testnet() else "eip155:8453"] + # USDC contract + public RPCs from the shared chain table + # (x402.EVM_NETWORKS), which the upto scheme's allowance reads use too. + net = EVM_NETWORKS["eip155:8453"] usdc_contract = net["usdc"] rpcs = list(net["rpcs"]) @@ -3141,13 +3135,12 @@ class AsyncLLMClient: Usage: async with AsyncLLMClient() as client: response = await client.chat("gpt-5.2", "Hello!") - - # For testnet: - async with AsyncLLMClient(api_url="https://testnet.blockrun.ai/api") as client: - response = await client.chat("openai/gpt-oss-20b", "Hello!") """ DEFAULT_API_URL = "https://blockrun.ai/api" + # Deprecated: the testnet was retired on 2026-10-02. Kept so attribute + # access does not break on upgrade; constructing a client with it raises + # RetiredEndpointError. TESTNET_API_URL = "https://testnet.blockrun.ai/api" DEFAULT_MAX_TOKENS = 1024 @@ -4154,7 +4147,7 @@ async def _handle_payment_and_retry_raw( recipient=details["recipient"], amount=details["amount"], scheme=details.get("scheme"), - network=details.get("network", "eip155:84532" if self.is_testnet() else "eip155:8453"), + network=details.get("network", "eip155:8453"), resource_url=validate_resource_url(resource.get("url", url), self.api_url), resource_description=resource.get("description", "BlockRun AI API call"), max_timeout_seconds=details.get("maxTimeoutSeconds", 300), @@ -4294,7 +4287,7 @@ async def _handle_get_payment_and_retry( recipient=details["recipient"], amount=details["amount"], scheme=details.get("scheme"), - network=details.get("network", "eip155:84532" if self.is_testnet() else "eip155:8453"), + network=details.get("network", "eip155:8453"), resource_url=validate_resource_url(resource.get("url", url), self.api_url), resource_description=resource.get("description", "BlockRun AI API call"), max_timeout_seconds=details.get("maxTimeoutSeconds", 300), @@ -4734,8 +4727,12 @@ def get_wallet_address(self) -> str: return self.account.address def is_testnet(self) -> bool: - """Check if client is configured for testnet.""" - return "testnet.blockrun.ai" in self.api_url + """Deprecated: always ``False``. + + BlockRun's testnet was retired on 2026-10-02 and a client can no longer + be constructed against it. Kept so existing callers do not break. + """ + return False def _billing_meta(self) -> dict[str, str | None]: """Billing metadata for cost-log entries.""" @@ -4783,11 +4780,7 @@ async def get_balance(self) -> float: if self.api_key: raise wallet_only("get_balance") """ - Get USDC balance on Base network. - - Automatically detects mainnet vs testnet based on API URL: - - Mainnet: Base (Chain ID 8453) - - Testnet: Base Sepolia (Chain ID 84532) + Get USDC balance on Base mainnet (Chain ID 8453). Returns: float: USDC balance (6 decimal places normalized) @@ -4796,12 +4789,9 @@ async def get_balance(self) -> float: balance = await client.get_balance() print(f"Balance: ${balance:.2f} USDC") """ - # USDC contracts - # Mainnet: Base - # Testnet: Base Sepolia - # Contract + public RPCs from the shared chain table (x402.EVM_NETWORKS), - # which the upto scheme's allowance reads use too. - net = EVM_NETWORKS["eip155:84532" if self.is_testnet() else "eip155:8453"] + # USDC contract + public RPCs from the shared chain table + # (x402.EVM_NETWORKS), which the upto scheme's allowance reads use too. + net = EVM_NETWORKS["eip155:8453"] usdc_contract = net["usdc"] rpcs = list(net["rpcs"]) @@ -4846,68 +4836,47 @@ async def __aexit__(self, exc_type, exc_val, exc_tb): # ============================================================================= -# Testnet Convenience Functions +# Retired testnet helpers # ============================================================================= -def testnet_client(private_key: str | None = None, **kwargs) -> LLMClient: - """ - Create a testnet LLM client for development and testing. - - This is a convenience function that creates an LLMClient configured - for the BlockRun testnet (Base Sepolia). +def testnet_client(private_key: str | None = None, **kwargs: Any) -> LLMClient: + """RETIRED — BlockRun's testnet was shut down on 2026-10-02. - Args: - private_key: Base Sepolia wallet private key (or set BLOCKRUN_WALLET_KEY env var) - **kwargs: Additional arguments passed to LLMClient + testnet.blockrun.ai (Base Sepolia) no longer serves requests. Use the + mainnet client instead:: - Returns: - LLMClient configured for testnet + from blockrun_llm import LLMClient - Example: - from blockrun_llm import testnet_client + client = LLMClient() # USDC on Base, https://blockrun.ai/api - client = testnet_client() # Uses BLOCKRUN_WALLET_KEY - response = client.chat("openai/gpt-oss-20b", "Hello!") + To develop without spending USDC, call a free model, e.g. + ``client.smart_chat(prompt, routing_profile="free")``: it settles $0, so an + unfunded wallet works. - Testnet Setup: - 1. Get testnet ETH from https://www.alchemy.com/faucets/base-sepolia - 2. Get testnet USDC from https://faucet.circle.com/ - 3. Use your wallet with testnet funds + Kept as a raising stub rather than deleted so upgrading does not break + imports; calling it fails immediately instead of with a DNS error. - Available Testnet Models: - - openai/gpt-oss-20b - - openai/gpt-oss-120b + :raises RetiredEndpointError: always. """ - return LLMClient( - private_key=private_key, - api_url=LLMClient.TESTNET_API_URL, - **kwargs, - ) + raise RetiredEndpointError(testnet_retired_message("testnet_client() is retired.")) -async def async_testnet_client(private_key: str | None = None, **kwargs) -> AsyncLLMClient: - """ - Create an async testnet LLM client for development and testing. +def async_testnet_client(private_key: str | None = None, **kwargs: Any) -> AsyncLLMClient: + """RETIRED — BlockRun's testnet was shut down on 2026-10-02. - This is a convenience function that creates an AsyncLLMClient configured - for the BlockRun testnet (Base Sepolia). + testnet.blockrun.ai (Base Sepolia) no longer serves requests. Use the + mainnet client instead:: - Args: - private_key: Base Sepolia wallet private key (or set BLOCKRUN_WALLET_KEY env var) - **kwargs: Additional arguments passed to AsyncLLMClient + from blockrun_llm import AsyncLLMClient - Returns: - AsyncLLMClient configured for testnet + async with AsyncLLMClient() as client: # USDC on Base + response = await client.chat("nvidia/nemotron-3.5-lightning", "Hello!") - Example: - from blockrun_llm import async_testnet_client + Kept as a raising stub rather than deleted so upgrading does not break + imports. It is a plain function, not a coroutine, so it raises at the call + whether or not the result would have been awaited. - async with async_testnet_client() as client: - response = await client.chat("openai/gpt-oss-20b", "Hello!") + :raises RetiredEndpointError: always. """ - return AsyncLLMClient( - private_key=private_key, - api_url=AsyncLLMClient.TESTNET_API_URL, - **kwargs, - ) + raise RetiredEndpointError(testnet_retired_message("async_testnet_client() is retired.")) diff --git a/blockrun_llm/validation.py b/blockrun_llm/validation.py index 2ecdd22..e1ca74e 100644 --- a/blockrun_llm/validation.py +++ b/blockrun_llm/validation.py @@ -22,6 +22,45 @@ # Localhost domains that are allowed to use HTTP LOCALHOST_DOMAINS = {"localhost", "127.0.0.1"} +# BlockRun's Base Sepolia testnet gateway. Retired on 2026-10-02: the service +# was shut down and the hostname no longer resolves, so a client pointed at it +# is refused up front instead of failing later with a DNS error. +RETIRED_TESTNET_HOST = "testnet.blockrun.ai" + + +def testnet_retired_message(subject: str) -> str: + """The error text for anything that would reach the retired testnet. + + ``subject`` names what the caller tried (a helper or a URL), so the message + says which line to change; the rest names the mainnet replacement. + """ + return ( + f"{subject} BlockRun's testnet (testnet.blockrun.ai, Base Sepolia, chain " + "84532) was retired on 2026-10-02 and no longer serves requests. Use the " + "mainnet client instead: `from blockrun_llm import LLMClient; client = " + "LLMClient()` (or `AsyncLLMClient()`), which pays USDC on Base at " + "https://blockrun.ai/api. To develop without spending USDC, call a free " + 'model, e.g. `client.smart_chat(prompt, routing_profile="free")`: it ' + "settles $0, so an unfunded wallet works." + ) + + +def reject_retired_testnet_url(url: str) -> None: + """Raise ``RetiredEndpointError`` if ``url`` points at the retired testnet. + + Raises: + RetiredEndpointError: If the URL's host is ``testnet.blockrun.ai``. + """ + try: + host = (urlparse(url).hostname or "").lower() + except ValueError: + return + if host == RETIRED_TESTNET_HOST: + from .types import RetiredEndpointError + + raise RetiredEndpointError(testnet_retired_message(f"{url} is retired.")) + + # Known LLM providers (for optional validation) KNOWN_PROVIDERS = { "openai", @@ -533,6 +572,8 @@ def validate_api_url(url: str) -> None: Raises: ValueError: If the URL is invalid or insecure + RetiredEndpointError: If the URL points at the retired testnet + (testnet.blockrun.ai, retired 2026-10-02) Example: >>> validate_api_url("https://blockrun.ai/api") @@ -549,6 +590,10 @@ def validate_api_url(url: str) -> None: if not parsed.netloc: raise ValueError("API URL must include domain") + # Before the HTTPS check, so an http:// testnet URL gets the retirement + # message rather than a scheme complaint. + reject_retired_testnet_url(url) + # Require HTTPS for non-localhost URLs is_localhost = parsed.netloc.split(":")[0] in LOCALHOST_DOMAINS diff --git a/blockrun_llm/x402.py b/blockrun_llm/x402.py index c025241..b7261fb 100644 --- a/blockrun_llm/x402.py +++ b/blockrun_llm/x402.py @@ -20,7 +20,9 @@ BASE_CHAIN_ID = 8453 USDC_BASE = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913" -# Chain and token constants for testnet (Base Sepolia) +# Chain and token constants for Base Sepolia. BlockRun's testnet gateway on it +# was retired on 2026-10-02; the chain stays in EVM_NETWORKS so the x402 signer +# can still pay a 402 from any other server that names it. BASE_SEPOLIA_CHAIN_ID = 84532 USDC_BASE_SEPOLIA = "0x036CbD53842c5426634e7929541eC2318f3dCF7e" @@ -88,7 +90,7 @@ ), }, } -# The pre-CAIP alias this SDK accepted for the testnet. +# The pre-CAIP alias this SDK accepted for Base Sepolia. _NETWORK_ALIASES = {"base-sepolia": "eip155:84532"} diff --git a/examples/sweep_all_chat_models.py b/examples/sweep_all_chat_models.py index 161c493..62f6738 100644 --- a/examples/sweep_all_chat_models.py +++ b/examples/sweep_all_chat_models.py @@ -227,10 +227,6 @@ def preflight() -> LLMClient: client = LLMClient() - if client.is_testnet(): - sys.stderr.write("ERROR: client resolved to testnet. refusing to run.\n") - sys.exit(2) - print(f"wallet : {mask_address(client.get_wallet_address())}") print(f"api url : {client.api_url}") print("network : Base mainnet") diff --git a/integrations/llama-index-llms-blockrun/README.md b/integrations/llama-index-llms-blockrun/README.md index 0e6f5e7..5486447 100644 --- a/integrations/llama-index-llms-blockrun/README.md +++ b/integrations/llama-index-llms-blockrun/README.md @@ -117,7 +117,7 @@ https://blockrun.ai/api/v1/models. | `max_tokens` | unset | The SDK sends 1024 when unset | | `context_window` | from catalog | Read once from `/v1/models`; set it to skip that request | | `max_cost_per_call` | unset | USD ceiling per call | -| `api_url` | chain's mainnet | `https://testnet.blockrun.ai/api` for Base Sepolia | +| `api_url` | chain's mainnet | `https://arc.blockrun.ai/api` for Circle Arc | | `timeout` | 600 s | Reasoning models can think for minutes | | `additional_kwargs` | `{}` | Sent with every request, e.g. `top_p`, `stop`, `response_format` | | `is_function_calling_model` | `True` | Set `False` for a model without tool support | diff --git a/integrations/llama-index-llms-blockrun/llama_index/llms/blockrun/base.py b/integrations/llama-index-llms-blockrun/llama_index/llms/blockrun/base.py index c239e46..36f0e24 100644 --- a/integrations/llama-index-llms-blockrun/llama_index/llms/blockrun/base.py +++ b/integrations/llama-index-llms-blockrun/llama_index/llms/blockrun/base.py @@ -165,8 +165,8 @@ class BlockRun(FunctionCallingLLM): api_url: str | None = Field( default=None, description=( - "Gateway URL override, e.g. https://testnet.blockrun.ai/api for Base " - "Sepolia. Unset uses the chain's mainnet gateway." + "Gateway URL override, e.g. https://arc.blockrun.ai/api for Circle " + "Arc. Unset uses the chain's mainnet gateway." ), ) timeout: float | None = Field( diff --git a/integrations/llama-index-llms-blockrun/tests/test_llms_blockrun.py b/integrations/llama-index-llms-blockrun/tests/test_llms_blockrun.py index 9f29288..4a4f8c3 100644 --- a/integrations/llama-index-llms-blockrun/tests/test_llms_blockrun.py +++ b/integrations/llama-index-llms-blockrun/tests/test_llms_blockrun.py @@ -216,13 +216,13 @@ def test_unset_options_are_not_passed(self, recorded: dict[str, Any]) -> None: def test_set_options_are_passed(self, recorded: dict[str, Any]) -> None: BlockRun( model=MODEL, - api_url="https://testnet.blockrun.ai/api", + api_url="https://arc.blockrun.ai/api", timeout=30, max_cost_per_call=0.05, )._get_client() assert recorded["LLMClient"] == { "private_key": None, - "api_url": "https://testnet.blockrun.ai/api", + "api_url": "https://arc.blockrun.ai/api", "timeout": 30, "max_cost_per_call": 0.05, } diff --git a/pyproject.toml b/pyproject.toml index 6cf89f9..568cc58 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "blockrun-llm" -version = "1.24.1" +version = "1.24.2" description = "BlockRun SDK - Pay-per-request AI (LLM, Image, Video, Music, Voice) via x402 on Base and Solana" readme = "README.md" license = "MIT" diff --git a/tests/unit/test_retired_testnet.py b/tests/unit/test_retired_testnet.py new file mode 100644 index 0000000..ec82eb2 --- /dev/null +++ b/tests/unit/test_retired_testnet.py @@ -0,0 +1,150 @@ +"""BlockRun's testnet must fail fast and say what to use instead. + +testnet.blockrun.ai (Base Sepolia, chain 84532) was retired on 2026-10-02: the +Cloud Run service and its domain mapping were deleted, so the hostname no +longer resolves. The public names stay importable so upgrading does not break +`from blockrun_llm import testnet_client`; calling them, or pointing any client +at the old URL, raises RetiredEndpointError naming the mainnet replacement +instead of surfacing a DNS error on the first request. +""" + +import pytest + +import blockrun_llm +from blockrun_llm import ( + AsyncLLMClient, + ImageClient, + LLMClient, + RetiredEndpointError, + async_testnet_client, + testnet_client, +) +from blockrun_llm.types import BlockrunError +from blockrun_llm.validation import validate_api_url + +# Any well-formed key: these tests never reach the network. +TEST_KEY = "0x" + "11" * 32 +TESTNET_URL = "https://testnet.blockrun.ai/api" + + +@pytest.fixture(autouse=True) +def _wallet_rail(monkeypatch): + # An API key in the environment would put the client on the account rail, + # which never reads api_url; these tests are about the x402 gateway URL. + monkeypatch.delenv("BLOCKRUN_API_KEY", raising=False) + monkeypatch.delenv("BLOCKRUN_API_URL", raising=False) + + +def test_names_stay_importable(): + # Upgrading must not turn into an ImportError for existing callers. + assert "testnet_client" in blockrun_llm.__all__ + assert "async_testnet_client" in blockrun_llm.__all__ + assert LLMClient.TESTNET_API_URL == TESTNET_URL + assert AsyncLLMClient.TESTNET_API_URL == TESTNET_URL + + +def test_retired_error_is_an_sdk_error(): + assert issubclass(RetiredEndpointError, BlockrunError) + + +def test_testnet_client_raises(): + with pytest.raises(RetiredEndpointError, match="2026-10-02") as exc: + testnet_client() + message = str(exc.value) + assert "testnet_client()" in message + assert "LLMClient()" in message + + +def test_testnet_client_raises_with_arguments(): + # The old signature still binds, so callers get the retirement error, not + # a TypeError about unexpected arguments. + with pytest.raises(RetiredEndpointError, match="2026-10-02"): + testnet_client(private_key=TEST_KEY, timeout=30) + + +def test_async_testnet_client_raises_at_call(): + # A plain function, so it raises whether the caller awaits it, + # `async with`s it or just calls it. + with pytest.raises(RetiredEndpointError, match="2026-10-02") as exc: + async_testnet_client(TEST_KEY) + message = str(exc.value) + assert "async_testnet_client()" in message + assert "AsyncLLMClient()" in message + + +@pytest.mark.asyncio +async def test_async_testnet_client_raises_when_awaited(): + with pytest.raises(RetiredEndpointError, match="2026-10-02"): + await async_testnet_client() + + +def test_message_points_at_mainnet_and_the_free_tier(): + with pytest.raises(RetiredEndpointError) as exc: + testnet_client() + message = str(exc.value) + assert "https://blockrun.ai/api" in message + assert 'routing_profile="free"' in message + + +@pytest.mark.parametrize("cls", [LLMClient, AsyncLLMClient]) +def test_client_refuses_the_testnet_url(cls): + with pytest.raises(RetiredEndpointError, match="2026-10-02"): + cls(private_key=TEST_KEY, api_url=TESTNET_URL) + + +@pytest.mark.parametrize("cls", [LLMClient, AsyncLLMClient]) +def test_client_refuses_the_deprecated_constant(cls): + with pytest.raises(RetiredEndpointError, match="2026-10-02"): + cls(private_key=TEST_KEY, api_url=cls.TESTNET_API_URL) + + +def test_client_refuses_the_testnet_url_from_env(monkeypatch): + monkeypatch.setenv("BLOCKRUN_API_URL", TESTNET_URL) + with pytest.raises(RetiredEndpointError, match="2026-10-02"): + LLMClient(private_key=TEST_KEY) + + +def test_other_clients_refuse_it_too(): + # The check lives in validate_api_url, so every client that validates its + # gateway URL refuses the retired host the same way. + with pytest.raises(RetiredEndpointError, match="2026-10-02"): + ImageClient(private_key=TEST_KEY, api_url=TESTNET_URL) + + +@pytest.mark.parametrize( + "url", + [ + TESTNET_URL, + "https://testnet.blockrun.ai", + "https://TESTNET.blockrun.ai/api/", + # Retirement wins over the HTTPS complaint: the fix is the host. + "http://testnet.blockrun.ai/api", + ], +) +def test_validate_api_url_refuses_the_testnet_host(url): + with pytest.raises(RetiredEndpointError, match="2026-10-02"): + validate_api_url(url) + + +@pytest.mark.parametrize( + "url", + [ + "https://blockrun.ai/api", + "https://sol.blockrun.ai/api", + "https://arc.blockrun.ai/api", + "http://localhost:3000", + # Only the retired host is refused, not anything containing "testnet". + "https://testnet.example.com/api", + ], +) +def test_validate_api_url_accepts_live_gateways(url): + validate_api_url(url) + + +def test_mainnet_client_is_not_testnet(): + client = LLMClient(private_key=TEST_KEY) + try: + assert client.api_url == "https://blockrun.ai/api" + assert client.is_testnet() is False + finally: + client.close()