Commit Graph
46 Commits
Author SHA1 Message Date
Jeroen UbbinkandClaude Opus 4.8 d4657dca5a docs: reflect the optional, auto-generated secret key
The secret-key docs still said ROUTSTR_SECRET_KEY was required and that
the node would not start without it. Update the README, .env.example, and
the provider docs (configuration, quickstart, deployment) to the current
behaviour: the key is optional; when unset the node generates one beside
the database, so it persists on the same volume as the data, and prints a
one-time back-it-up notice; set it explicitly to manage the key yourself.
Switch the generation and reset snippets to `uv run python`, and add the
containerised reset variant.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-23 10:51:20 +02:00
redshift 892aed61cc Fix mypy: move type: ignore onto ASGITransport line 2026-07-16 16:43:52 +08:00
redshift 4287f038cf feat(ehbp): extract & use model name from Tinfoil usage metrics header
Tinfoil PR #385 added model=<name> to the X-Tinfoil-Usage-Metrics
header/trailer.  This commit uses that field for accurate billing.

Changes in routstr/upstream/ehbp.py:

- parse_tinfoil_usage_metrics(): extract the model= field as a string
  alongside the existing token counts (previously silently discarded
  because int() failed on it).

- _build_cost_info(): accept optional actual_model parameter propagated
  through to callers when a real mismatch is detected.

- _compute_ehbp_actual_cost(): compare the served model against
  model_obj.forwarded_model_id (the expected upstream ID) rather than
  model_obj.id (the client-facing alias).  This prevents spurious
  mismatches when a node runner maps e.g. tinfoil-glm-5-2 -> glm-5-2
  and the header correctly reports glm-5-2.  On a genuine mismatch
  (failover to a different upstream model), look up the actual model's
  pricing via get_model_instance() (forwarded_model_id values are
  registered as routable aliases in the global model map).

- forward_ehbp_request() / forward_ehbp_x_cashu_request(): use the
  actual served model for payment finalization and logging when a
  mismatch is detected.

Tests: 6 new scenarios (alias match, real mismatch with alias, unknown
model fallback, old-format compat, cache token details + model), plus
forwarded_model_id set on all existing mock model objects to keep them
passing.  All 49 Tinfoil/EHBP unit tests pass.
2026-07-10 09:57:10 +05:30
redshift 82fd2c08a7 Merge branch 'main' of https://github.com/Routstr/routstr-core into ehbp-proxy-refactor 2026-07-10 12:12:51 +08:00
9qeklajc e2aa02307b explicit code for error report & update doc 2026-07-05 23:05:53 +02:00
redshift ab5596ed70 remove .well-known/ from Tinfoil attestation routing
Tinfoil's proxy server guide only requires /attestation (GET) and
/v1/chat/completions + /v1/responses (POST). The .well-known/ path was
never requested by Tinfoil and was incorrectly added to:
- _API_PATH_PREFIXES (prefix gate)
- the unauthenticated GET bypass branch
- the Tinfoil integration docs

Remove it from all three.
2026-07-02 20:09:58 +05:30
redshift a8f60643e0 feat: return per-request cost headers on EHBP/Tinfoil responses
EHBP response bodies are opaque encrypted blobs, so cost cannot be injected
into JSON like the normal proxy flow. Instead, surface cost as response headers:

  X-Routstr-Cost-Msats       — total msats charged (bearer + x-cashu)
  X-Routstr-Cost-Usd         — USD equivalent (bearer only)
  X-Routstr-Input-Cost-Msats — msats attributed to input tokens
  X-Routstr-Output-Cost-Msats— msats attributed to output tokens

- Refactor _compute_ehbp_actual_cost from int→dict to carry full cost breakdown
- Add _build_cost_info() and _inject_cost_response_headers() helpers
- Capture adjust_payment_for_tokens return in bearer path (was discarded)
- Update CORS expose_headers, docs, and unit tests
2026-06-23 20:42:01 +08:00
redshift 2e350e082b feat: add Tinfoil direct blind-upstream integration
Add TinfoilUpstreamProvider that uses inference.tinfoil.sh as a direct
EHBP upstream. Routstr acts as a blind relay: it forwards the opaque
encrypted body to the Tinfoil enclave without ever seeing plaintext,
and bills from the X-Tinfoil-Usage-Metrics response header.

- New routstr/upstream/tinfoil.py: fetches models from public
  GET /v1/models, parses Tinfoil pricing into standard Model/Pricing
  schema, supports_ehbp=True, proxies /attestation to atc.tinfoil.sh
- Updated routstr/upstream/ehbp.py:
  - parse_tinfoil_usage_metrics() parses prompt=N,completion=N header
  - _resolve_ehbp_target_url() honors X-Tinfoil-Enclave-Url from SDK
  - _strip_proxy_headers() removes proxy-only headers before forwarding
  - _compute_ehbp_actual_cost() converts usage to msats via calculate_cost
  - forward_ehbp_request() finalizes with exact token cost when usage
    header is present (non-streaming), falls back to max-cost otherwise
  - forward_ehbp_x_cashu_request() computes refund from actual cost
    when usage is available
- Updated routstr/proxy.py: forward /attestation and /.well-known/ paths
  without model/cost/auth lookups
- Updated routstr/upstream/__init__.py and helpers.py: register and
  auto-seed Tinfoil provider from TINFOIL_API_KEY env var
- Updated .env.example with TINFOIL_API_KEY
- 22 new unit tests in tests/unit/test_tinfoil_integration.py
- Updated docs/tinfoil-direct-integration.md and docs/ehbp-proxy-support.md
  with implementation status and billing behavior table
2026-06-21 13:16:01 +08:00
redshift 24b90af6e6 refactor: move EHBP logic to dedicated module with explicit opt-in
- Add supports_ehbp + get_ehbp_forwarding_target hooks to BaseUpstreamProvider,
  keeping base.py minimal (no large forwarding methods)
- Create routstr/upstream/ehbp.py with forward_ehbp_request and
  forward_ehbp_x_cashu_request helpers, plus max-cost finalization
- PPQAIUpstreamProvider: set supports_ehbp = True, implement target to
  /private/v1/... with X-Private-Model header
- proxy.py: filter to EHBP-capable providers, route to ehbp helpers
- Fix bearer EHBP payment: reserve upfront, finalize max cost on success
- Fix X-Cashu EHBP: refund full token on failure, refund excess on success
- Update docs/ehbp-proxy-support.md to reflect new architecture
2026-06-20 17:18:53 +08:00
Bilthon f2ef63da62 refactor(balance): remove unreachable cashu-refund-by-hash endpoint 2026-05-28 10:25:25 -05:00
9qeklajc 632244e54f add rop-08 lightning invoice support 2026-05-20 23:24:24 +02:00
9qeklajc 59773e972b configure payment 2026-05-09 00:00:18 +02:00
9qeklajc 10969e0719 update deployment 2026-05-05 22:40:47 +02:00
redshift f50cb31749 Updated deployment docs 2026-04-11 22:15:50 +01:00
Evan Yang 8fc1b6484c Add Nostr analytics snapshots and expand stats model coverage 2026-03-13 15:55:29 +08:00
9qeklajc 8c2eb55760 Merge branch 'main' into v0.4.0
# Conflicts:
#	docs/provider/quickstart.md
2026-02-18 23:50:09 +01:00
9qeklajc b3c5e4cbf6 add doc 2026-02-15 17:06:07 +01:00
9qeklajc 030c2f65e4 add missing info 2026-02-13 22:22:41 +01:00
9qeklajc 5f376d716d clean up 2026-02-13 21:15:33 +01:00
9qeklajc d889274f84 update doc 2026-02-12 23:25:59 +01:00
9qeklajc 8973627b5f update doc 2026-02-12 21:19:12 +01:00
9qeklajc d3dd8318e4 update doc 2026-02-12 21:15:44 +01:00
Shroominic c6e401c3f6 Merge branch 'main' into v0.3.0
# Conflicts:
#	routstr/proxy.py
2026-01-30 10:54:35 +08:00
9qeklajc bbf1e65a5d clean up & add docs 2026-01-26 20:44:23 +01:00
Shroominic 60e0eebd05 tiny docs fixes 2026-01-24 21:16:58 +08:00
Shroominic 2210e9be6c rm old docs 2026-01-24 17:55:50 +08:00
Shroominic 9c66789665 improved docs 2026-01-24 17:55:45 +08:00
9qeklajc cfe03d6dcb remove redundant setting & doc 2025-11-10 22:59:32 +01:00
9qeklajc 80b6acbf4b add docs 2025-11-10 22:40:35 +01:00
Shroominic 4b36fb8d6f change version 2025-10-12 13:03:29 +08:00
Shroominic c90abe9e79 update version 2025-10-04 20:12:28 +08:00
Shroominic 5fb583be55 v0.1.4-dev 2025-09-22 11:11:36 +01:00
Shroominic 9ab269dd8f ⬆️ v0.1.3 2025-09-15 17:55:20 +01:00
Shroominic 84ff9f5dc3 update default relays 2025-09-11 13:38:04 +01:00
Shroominic 44030ddbe5 docs: simplify discovery config (RELAYS only); drop OpenRouter BASE_URL mentions 2025-09-08 12:26:22 +01:00
Shroominic bb9991e7a5 docs: update configuration/pricing docs and compose with FIXED_* vars 2025-09-08 10:53:32 +01:00
Shroominic cc9e387d3a ⬆️ v0.1.2 2025-09-04 21:47:13 +01:00
Shroominic 124fbedf2a update core config docs 2025-09-04 15:29:06 +01:00
Shroominic fa4b78abec azure openai docs 2025-09-04 15:29:06 +01:00
Shroominic 4b40e9010d correct env var names 2025-09-01 21:42:25 +01:00
Shroominic 2311aa981e fix 2025-08-25 02:13:40 -03:00
Shroominic f1d4dd6ff4 edits 2025-08-25 01:56:09 -03:00
Shroominic 11c8902dde edits 2025-08-25 01:48:46 -03:00
Shroominic bedca877ce fmt 2025-08-25 01:10:10 -03:00
Shroominic efa3e18bf9 routstr core docs 2025-08-25 01:09:39 -03:00
Cursor Agentanddb2002dominic d4c1389249 docs: Add comprehensive documentation for Routstr Core project
Co-authored-by: db2002dominic <db2002dominic@gmail.com>
2025-08-25 01:17:40 +00:00