mirror of
https://github.com/Routstr/routstr-core.git
synced 2026-08-09 02:54:37 +00:00
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
40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
from .anthropic import AnthropicUpstreamProvider
|
|
from .azure import AzureUpstreamProvider
|
|
from .base import BaseUpstreamProvider
|
|
from .fireworks import FireworksUpstreamProvider
|
|
from .gemini import GeminiUpstreamProvider
|
|
from .generic import GenericUpstreamProvider
|
|
from .groq import GroqUpstreamProvider
|
|
from .ollama import OllamaUpstreamProvider
|
|
from .openai import OpenAIUpstreamProvider
|
|
from .openrouter import OpenRouterUpstreamProvider
|
|
from .perplexity import PerplexityUpstreamProvider
|
|
from .ppqai import PPQAIUpstreamProvider
|
|
from .routstr import RoutstrUpstreamProvider
|
|
from .tinfoil import TinfoilUpstreamProvider
|
|
from .xai import XAIUpstreamProvider
|
|
|
|
upstream_provider_classes: list[type[BaseUpstreamProvider]] = [
|
|
AnthropicUpstreamProvider,
|
|
AzureUpstreamProvider,
|
|
FireworksUpstreamProvider,
|
|
GeminiUpstreamProvider,
|
|
GenericUpstreamProvider,
|
|
GroqUpstreamProvider,
|
|
OllamaUpstreamProvider,
|
|
OpenAIUpstreamProvider,
|
|
OpenRouterUpstreamProvider,
|
|
PerplexityUpstreamProvider,
|
|
PPQAIUpstreamProvider,
|
|
RoutstrUpstreamProvider,
|
|
TinfoilUpstreamProvider,
|
|
XAIUpstreamProvider,
|
|
]
|
|
"""List of all upstream classes"""
|
|
|
|
__all__ = [
|
|
"BaseUpstreamProvider",
|
|
*[cls.__name__ for cls in upstream_provider_classes],
|
|
"upstream_provider_classes",
|
|
]
|