Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 52 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ pip install "llama-index-llms-blockrun[solana]" # pay on Solana
```python
from llama_index.llms.blockrun import BlockRun

llm = BlockRun(model="openai/gpt-5.5") # USDC on Base
llm = BlockRun(model="openai/gpt-5.5", chain="solana") # USDC on Solana
llm = BlockRun(model="openai/gpt-6.2-sol") # USDC on Base
llm = BlockRun(model="openai/gpt-6.2-sol", chain="solana") # USDC on Solana
```

## Smart Routing (Router Core)
Expand All @@ -220,13 +220,13 @@ client = LLMClient()
# Auto-routes to the cheapest capable model
result = client.smart_chat("Summarize this changelog entry in one line")
print(result.response)
print(result.model) # 'google/gemini-2.5-flash'
print(result.model) # 'google/gemini-3.5-flash-lite'
print(result.routing.task_type) # 'chat'
print(f"Saved {result.routing.savings * 100:.0f}%") # 'Saved 90%'

# Complex reasoning task -> routes to a reasoning model
# Proofs and step-by-step math classify into the REASONING tier
result = client.smart_chat("Prove the Riemann hypothesis step by step")
print(result.model) # 'deepseek/deepseek-v4-pro'
print(result.model) # 'google/gemini-3.6-flash'
```

Routing works the same on every client — `LLMClient`, `AsyncLLMClient`,
Expand Down Expand Up @@ -255,7 +255,7 @@ same routing locally and returns the decision only:

```python
decision = client.route("Prove the Riemann hypothesis step by step")
print(decision.model) # 'deepseek/deepseek-v4-pro'
print(decision.model) # 'google/gemini-3.6-flash'
print(decision.tier) # 'REASONING'
print(decision.task_type) # 'reasoning'
print(decision.candidates) # ordered chain; smart_chat walks it on a 5xx/timeout
Expand Down Expand Up @@ -305,18 +305,19 @@ Three stages:

The four capability tiers:

| Tier | Example Tasks | Auto Profile Model |
|------|---------------|-------------------|
| SIMPLE | Short questions, definitions | google/gemini-2.5-flash |
| MEDIUM | Code snippets, explanations | google/gemini-3.5-flash (code); google/gemini-2.5-flash (plain chat) |
| Tier | Example Tasks | Auto Profile Primary |
|------|---------------|----------------------|
| SIMPLE | Short questions, definitions | google/gemini-3.5-flash-lite |
| MEDIUM | Code snippets, explanations | google/gemini-3.6-flash |
| COMPLEX | Architecture, long documents | google/gemini-3.1-pro |
| REASONING | Proofs, math, multi-step reasoning | deepseek/deepseek-v4-pro |
| REASONING | Proofs, math, multi-step reasoning | deepseek/deepseek-reasoner |

These are the picks `client.route()` returned against the live catalog on
2026-10-02. The task ranker can move a tier's fallback ahead of its configured
primary — REASONING's primary is `deepseek/deepseek-reasoner`, but proofs and
step-by-step math rank `deepseek/deepseek-v4-pro` first — so check
`decision.model` rather than relying on this table.
The primaries come from `blockrun_llm.router_core.DEFAULT_ROUTING_CONFIG`. The
task ranker can move a tier's fallback ahead of its primary. On 2026-11-27,
`client.route()` against the live catalog picked the primary for short chat
(SIMPLE) and for code (MEDIUM), but ranked `google/gemini-3.6-flash` ahead of
`deepseek/deepseek-reasoner` for proofs and step-by-step math (REASONING).
Check `decision.model` rather than relying on this table.

Every decision is explainable — `result.routing` carries the tier, the task
type, the confidence, the ranked `candidates`, the per-candidate
Expand Down Expand Up @@ -423,7 +424,7 @@ print(f"Balance: ${client.get_balance():.2f} USDC")
#### Phase 2 — Every request pays itself (automatic x402)

```python
reply = client.chat("anthropic/claude-sonnet-4.6", "Explain x402 in one line")
reply = client.chat("anthropic/claude-sonnet-5.5", "Explain x402 in one line")
```

That single call does all of this under the hood:
Expand Down Expand Up @@ -528,12 +529,13 @@ and `client.list_image_models()` return exactly what the gateway is charging.
### OpenAI GPT-6 Family

The GPT-6 generation: Astra is the flagship for long-horizon agentic work and
computer use, Sol the cost-efficient tier for complex coding (`gpt-6.1-sol` is the
refreshed Sol), Luna the fast low-cost tier.
computer use, Sol the cost-efficient tier for complex coding (`gpt-6.2-sol` is the
newest Sol, `gpt-6.1-sol` the one before it), Luna the fast low-cost tier.

| Model | Context |
|---|---|
| `openai/gpt-6-astra` | 1.05M |
| `openai/gpt-6.2-sol` | 1.05M |
| `openai/gpt-6.1-sol` | 1.05M |
| `openai/gpt-6-sol` | 1.05M |
| `openai/gpt-6-luna` | 1.05M |
Expand Down Expand Up @@ -568,7 +570,7 @@ longer at the same token price.
| `openai/gpt-5.2-pro` | 400K | |
| `openai/gpt-5.1` | 400K | Configurable reasoning effort |
| `openai/gpt-5.3-codex` | 400K | Coding/agentic SKU |
| `openai/gpt-5-mini` | 200K | |
| `openai/gpt-5-mini` | 200K | Retiring 2026-12-11: the gateway will redirect it to `openai/gpt-5.6-luna` |

### OpenAI GPT-4 Family

Expand All @@ -581,12 +583,11 @@ longer at the same token price.

### OpenAI O-Series (Reasoning)

| Model | Context |
|---|---|
| `openai/o1` | 200K |
| `openai/o3` | 200K |
| `openai/o3-mini` | 128K |
| `openai/o4-mini` | 128K |
| Model | Context | Notes |
|---|---|---|
| `openai/o3` | 200K | Retiring 2026-12-11: the gateway will redirect it to `openai/gpt-5.4-mini` |

> **Retired**: OpenAI shut down `o1`, `o1-mini`, `o3-mini` and `o4-mini`. The gateway redirects pinned callers to `openai/gpt-5.4-mini`, so those ids still return 200, from a different model.

### Anthropic Claude

Expand All @@ -608,20 +609,21 @@ longer at the same token price.

### Google Gemini

| Model | Context |
|---|---|
| `google/gemini-4-carbon` | 1M |
| `google/gemini-4-argon` | 1M |
| `google/gemini-3.1-pro` | 1M |
| `google/gemini-3.8-flash` | 1M |
| `google/gemini-3.6-flash` | 1M |
| `google/gemini-3.5-flash` | 1M |
| `google/gemini-3-flash-preview` | 1M |
| `google/gemini-3.5-flash-lite` | 1M |
| `google/gemini-3.1-flash-lite` | 1M |
| `google/gemini-2.5-pro` | 1M |
| `google/gemini-2.5-flash` | 1M |
| `google/gemini-2.5-flash-lite` | 1M |
| Model | Context | Notes |
|---|---|---|
| `google/gemini-4-carbon` | 1M | |
| `google/gemini-4-argon` | 1M | |
| `google/gemini-3.1-pro` | 1M | |
| `google/gemini-3.8-flash` | 1M | |
| `google/gemini-3.6-flash` | 1M | |
| `google/gemini-3-flash-preview` | 1M | |
| `google/gemini-3.5-flash-lite` | 1M | |
| `google/gemini-3.1-flash-lite` | 1M | |
| `google/gemini-2.5-pro` | 1M | Retiring 2026-12-01: the gateway will redirect it to `google/gemini-3.8-flash` |
| `google/gemini-2.5-flash` | 1M | Retiring 2026-12-01: the gateway will redirect it to `google/gemini-3.5-flash-lite` |
| `google/gemini-2.5-flash-lite` | 1M | |

> **Retired**: `google/gemini-3.5-flash` is redirected to `google/gemini-3.6-flash`, the model Google has been serving under that name.

### DeepSeek

Expand Down Expand Up @@ -1456,7 +1458,7 @@ print(response)

# With system prompt
response = client.chat(
"anthropic/claude-sonnet-4.6",
"anthropic/claude-sonnet-5.5",
"Write a haiku",
system="You are a creative poet."
)
Expand Down Expand Up @@ -1570,8 +1572,8 @@ async def main():
# Multiple requests concurrently
tasks = [
client.chat("openai/gpt-5.2", "What is 2+2?"),
client.chat("anthropic/claude-sonnet-4.6", "What is 3+3?"),
client.chat("google/gemini-2.5-flash", "What is 4+4?"),
client.chat("anthropic/claude-sonnet-5.5", "What is 3+3?"),
client.chat("google/gemini-3.5-flash-lite", "What is 4+4?"),
]
responses = await asyncio.gather(*tasks)
for r in responses:
Expand Down Expand Up @@ -1741,8 +1743,8 @@ Works the same on `AsyncLLMClient`, `SolanaLLMClient`, and `AsyncSolanaLLMClient
Every paid call appends one row. Example:

```
2026-05-21 15:44:46 chat anthropic/claude-sonnet-4.6 in= 3 out=4 $0.034137 0x6513d128…
2026-05-20 04:34:17 chat openai/gpt-5.5 in= 14 out=18 $0.001000 0x421796a3…
2026-05-21 15:44:46 chat anthropic/claude-sonnet-5.5 in= 3 out=4 $0.034137 0x6513d128…
2026-05-20 04:34:17 chat openai/gpt-6.2-sol in= 14 out=18 $0.001000 0x421796a3…
```

Columns: timestamp · endpoint tag (`chat`/`image`/`video`/`search`/…) · model
Expand Down Expand Up @@ -1783,7 +1785,7 @@ for row in logger.entries()[-5:]:
# Build your own row (e.g. for tests or custom adapters)
print(format_row(
endpoint="/v1/chat/completions",
model="openai/gpt-5.5",
model="openai/gpt-6.2-sol",
in_tokens=14,
out_tokens=18,
cost_usd=0.001,
Expand Down Expand Up @@ -1914,7 +1916,7 @@ from blockrun_llm import setup_agent_wallet

# Auto-creates wallet if none exists, returns ready client
client = setup_agent_wallet()
response = client.chat("openai/gpt-5.4", "Hello!")
response = client.chat("openai/gpt-6.2-sol", "Hello!")
```

For Solana:
Expand All @@ -1923,7 +1925,7 @@ For Solana:
from blockrun_llm import setup_agent_solana_wallet

client = setup_agent_solana_wallet()
response = client.chat("anthropic/claude-sonnet-4.6", "Hello!")
response = client.chat("anthropic/claude-sonnet-5.5", "Hello!")
```

Check wallet status:
Expand Down Expand Up @@ -2040,15 +2042,15 @@ from blockrun_llm import AnthropicClient
client = AnthropicClient() # Auto-detects wallet, auto-pays

response = client.messages.create(
model="claude-sonnet-4-6",
model="claude-sonnet-5-5",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.content[0].text)

# Works with any BlockRun model in Anthropic format
response = client.messages.create(
model="openai/gpt-5.4",
model="openai/gpt-6.2-sol",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello from GPT!"}]
)
Expand Down
6 changes: 3 additions & 3 deletions blockrun_llm/anthropic_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

client = AnthropicClient()
response = client.messages.create(
model="claude-sonnet-4-6",
model="claude-sonnet-5-5",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello!"}]
)
Expand Down Expand Up @@ -116,15 +116,15 @@ class AnthropicClient:

client = AnthropicClient()
response = client.messages.create(
model="claude-sonnet-4-6",
model="claude-sonnet-5-5",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.content[0].text)

# Works with any BlockRun model in Anthropic format
response = client.messages.create(
model="openai/gpt-5.5",
model="openai/gpt-6.2-sol",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello from GPT!"}]
)
Expand Down
8 changes: 4 additions & 4 deletions blockrun_llm/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def _should_fallback(exc: Exception) -> bool:


# The gateway states the output-token ceiling it actually quoted in the 402's
# ``resource.description``, e.g. "claude-opus-4.8 ... 128000 max output tokens".
# ``resource.description``, e.g. "claude-opus-5.5 ... 128000 max output tokens".
#
# The alternation is bounded on both branches and the leading lookbehind stops a
# match from starting mid-number, so there is no super-linear backtracking. The
Expand Down Expand Up @@ -982,7 +982,7 @@ def route(

Example:
decision = client.route("Prove the Riemann hypothesis")
print(decision.model) # 'deepseek/deepseek-v4-pro'
print(decision.model) # 'google/gemini-3.6-flash'
print(decision.task_type) # 'reasoning'
print(decision.candidates) # ordered fallback chain
"""
Expand Down Expand Up @@ -1033,7 +1033,7 @@ def smart_chat(
Example:
result = client.smart_chat("What is 2+2?")
print(result.response) # '4'
print(result.model) # 'google/gemini-3.5-flash'
print(result.model) # 'google/gemini-3.6-flash'
print(result.routing.method) # 'portfolio'
print(f"Saved {result.routing.savings * 100:.0f}%")

Expand Down Expand Up @@ -1201,7 +1201,7 @@ def chat(
Simple 1-line chat interface.

Args:
model: Model ID (e.g., "openai/gpt-5.2", "anthropic/claude-sonnet-4.6", "openai/gpt-5.2")
model: Model ID (e.g., "openai/gpt-6.2-sol", "anthropic/claude-sonnet-5.5")
prompt: User message
system: Optional system prompt
max_tokens: Max tokens to generate (default: 1024)
Expand Down
2 changes: 1 addition & 1 deletion blockrun_llm/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
client = LLMClient()
result = client.smart_chat("What is 2+2?")
print(result.response) # '4'
print(result.model) # 'google/gemini-3.5-flash'
print(result.model) # 'google/gemini-3.6-flash'
print(f"Saved {result.routing.savings * 100:.0f}%")
"""

Expand Down
4 changes: 2 additions & 2 deletions blockrun_llm/solana_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,7 @@ def smart_chat(

Example:
result = client.smart_chat("What is 2+2?")
print(result.model) # 'google/gemini-2.5-flash'
print(result.model) # 'google/gemini-3.6-flash'
print(result.routing.method) # 'portfolio'
"""
decision = route_with_catalog(
Expand Down Expand Up @@ -4172,7 +4172,7 @@ class AsyncSolanaLLMClient:

client = AsyncSolanaLLMClient() # SOLANA_WALLET_KEY env
resp = await client.chat_completion(
"openai/gpt-5.5",
"openai/gpt-6.2-sol",
[{"role": "user", "content": "gm Solana"}],
)
await client.close()
Expand Down
4 changes: 2 additions & 2 deletions blockrun_llm/tx_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
line to a project-local file — default ``./log/transactions.log``. The
format is designed to be eyeballable in a terminal and ``grep``-friendly::

2026-05-21 15:44:46 chat anthropic/claude-sonnet-4.6 in= 3 out=4 $0.034137 0x6513d128...
2026-05-21 15:44:46 chat anthropic/claude-sonnet-5.5 in= 3 out=4 $0.034137 0x6513d128...

Columns (single space between blocks, two spaces between fields):

Expand Down Expand Up @@ -426,7 +426,7 @@ class TransactionLogger:
request=body,
response=chat_response,
cost_usd=0.034137,
model="anthropic/claude-sonnet-4.6",
model="anthropic/claude-sonnet-5.5",
settlement={"tx_hash": "0x6513d128…"},
)

Expand Down
2 changes: 1 addition & 1 deletion blockrun_llm/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ class SmartChatResponse(BaseModel):
Example:
result = client.smart_chat("What is 2+2?")
print(result.response) # '4'
print(result.model) # 'google/gemini-2.5-flash'
print(result.model) # 'google/gemini-3.6-flash'
print(f"Saved {result.routing.savings * 100:.0f}%")
"""

Expand Down
6 changes: 3 additions & 3 deletions examples/arbitrage_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ class ArbitrageAnalyzer:

# Model recommendations by use case
MODELS = {
"fast": "openai/gpt-5.4-nano", # $0.20/M input - quick analysis
"fast": "openai/gpt-6-luna", # $0.10/M input - quick analysis
"balanced": "anthropic/claude-haiku-4.5", # $1.00/M input - good reasoning
"deep": "anthropic/claude-sonnet-4.6", # $3.00/M input - thorough analysis
"frontier": "openai/gpt-5.5", # $5.00/M input - latest capabilities (1M context)
"deep": "anthropic/claude-sonnet-5.5", # $2.00/M input - thorough analysis
"frontier": "openai/gpt-6.2-sol", # $2.00/M input - latest capabilities (1.05M context)
}

def __init__(self, model_tier: str = "fast"):
Expand Down
8 changes: 4 additions & 4 deletions examples/benchmark_claude.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@

Examples
--------
# Solana gateway, claude-opus-4.7, 30 reqs @ concurrency 5, + cache probe
python benchmark_claude.py --chain solana --model anthropic/claude-opus-4.7 \
# Solana gateway, claude-opus-5.5, 30 reqs @ concurrency 5, + cache probe
python benchmark_claude.py --chain solana --model anthropic/claude-opus-5.5 \
--requests 30 --concurrency 5 --cache-probe

# Base gateway, sonnet, quick 10-req smoke
python benchmark_claude.py --chain base --model anthropic/claude-sonnet-4.6 \
python benchmark_claude.py --chain base --model anthropic/claude-sonnet-5.5 \
--requests 10 --concurrency 3
"""
from __future__ import annotations
Expand Down Expand Up @@ -248,7 +248,7 @@ def fmt(x: float) -> str:
def main() -> None:
p = argparse.ArgumentParser(description="Claude E2E benchmark via BlockRun gateway")
p.add_argument("--chain", choices=["solana", "base"], default="solana")
p.add_argument("--model", default="anthropic/claude-opus-4.7")
p.add_argument("--model", default="anthropic/claude-opus-5.5")
p.add_argument("--api-url", default=None, help="override gateway URL")
p.add_argument("--requests", type=int, default=20)
p.add_argument("--concurrency", type=int, default=5)
Expand Down
Loading
Loading