Skip to content

Latest commit

 

History

History
149 lines (118 loc) · 9.59 KB

self-route.md

File metadata and controls

149 lines (118 loc) · 9.59 KB

Self-route: use your own machine through the coordinator

Last updated: 2026-11-07

Send your normal Darkbloom API requests to the provider your account owns — free, end-to-end, through the same api.darkbloom.dev endpoint and SDK configuration — by adding one request header or pinning an API key. For operators who run a provider and also consume the network. Nothing changes on the provider; the policy lives entirely on the coordinator (coordinator/api/inference/self_route.go, resolveSelfRoutePolicy).

Self-route is not the local API: the local API is a socket on the provider Mac that your tools call directly (Only me or Both, me first); self-route is regular fleet traffic whose scheduler is told which machine may serve it.

Prerequisites

  • A provider linked to your account: darkbloom login on the Mac, then darkbloom start (quickstart). Ownership is the account that linked the device (Provider.AccountID), stamped by the coordinator; the header cannot name a machine.
  • A consumer API key issued to the same account.
  • The model you request downloaded and advertised on that machine (darkbloom models list).

Steps

  1. Choose how to opt in. Three signals, resolved server-side from the authenticated identity; none comes from the request body:

    Signal Scope Behaviour
    X-Darkbloom-Route: self one request Exclusive. Only providers owned by the calling account; free; never falls back to the paid fleet — an explicit error if your machine cannot serve
    X-Darkbloom-Route: prefer one request Prefer. Owned machine first (free when it serves), otherwise the paid fleet. Takes a normal balance reservation up front; billing is decided at settlement by who served
    API key self_route_only = true every request on that key Hard ceiling: exclusive self-route regardless of header. Set in the console key form (console-ui/src/components/api-keys/KeyForm.tsx) or PATCH the key with {"self_route_only": true} (coordinator/api/access/keys/handlers.go)

    Header values are trimmed and case-insensitive. A key with self_route_only ignores prefer.

  2. Send a request with the header:

    curl https://api.darkbloom.dev/v1/chat/completions \
      -H "Authorization: Bearer $DARKBLOOM_API_KEY" \
      -H "X-Darkbloom-Route: self" \
      -H "Content-Type: application/json" \
      -d '{"model":"<model-id>","messages":[{"role":"user","content":"hi"}]}'

    OpenAI SDKs accept extra headers (default_headers in Python, defaultHeaders in Node). The header is invisible to the body schema, so it also works with a sealed private-text body.

  3. Discover what your machine serves with the same header. GET /v1/models follows the resolved route mode (coordinator/api/catalog/models_endpoints.go, HandleListModels): with self (or a self_route_only key) it lists only models on your online owned machines; header-less and prefer requests see the public catalog.

    curl -s https://api.darkbloom.dev/v1/models \
      -H "Authorization: Bearer $DARKBLOOM_API_KEY" -H "X-Darkbloom-Route: self"
  4. Optionally keep the machine private. private_only = true under [coordinator] in provider.toml (provider-swift/Sources/ProviderCore/Config/ProviderConfig.swift, CoordinatorSettings.privateOnly) registers the provider as private-only: the coordinator serves it exclusively to the owner's self-route requests and never to the public fleet (gate reason private_only, coordinator/registry/routing_eligibility.go). It then earns nothing; restart after changing the key.

  5. In the console, the chat "Use my machine" toggle sends prefer (console-ui/src/lib/chat/stream.ts, forwarded upstream by console-ui/src/app/api/chat/route.ts); free-only routing there is the per-key self_route_only ceiling. Creating a My Machine only key in the API console adopts it as this browser's chat key when none is tracked (logout, chat 401, and untracked auto-provision drop a leftover darkbloom_console_key_id so a stale id cannot block that adopt); POST /v1/auth/keys (console auto-provision) also inherits self_route_only when every active key on the account is already machine-only, so it cannot mint an unrestricted "use everything" key beside a machine-only one.

What the coordinator relaxes — and what it does not

Self-route to an owned machine relaxes exactly two gates in the scheduler (coordinator/registry/scheduler.go, providerPassesRoutingGatesLocked; relaxTrust := owned && (pr.SelfRouteOnly || pr.PreferOwner)):

  • the hardware-trust floor (Registry.MinTrustLevel, set by EIGENINFERENCE_MIN_TRUST), so an un-enrolled or self_signed machine of yours can serve you;
  • private-only admission, so a private_only provider is eligible.

Everything else still applies: liveness, challenge freshness, runtime verification, private-text support, model/trait eligibility, and the APNs code-identity gate once enforcement is switched on. Levels and flags are explained in attestation; the mechanism in architecture/security/attestation.md.

Requests served by an owned machine are free; prefer requests that fall back to the fleet are charged normally. Settlement rules are in architecture/billing.md.

Verify

darkbloom status          # Trust: <level>, connected, models advertised

Then send a self request and confirm it succeeds while darkbloom logs -f shows the request on your machine; with darkbloom stop the same request returns 503 machine_offline.

Troubleshooting

Exclusive self-route fails fast with the real cause instead of queueing (coordinator/api/inference/self_route.go, selfRouteUnavailable):

Status / code Meaning Fix
409 no_linked_machine No provider is linked to the account that owns the key darkbloom login on the Mac under that account
503 machine_offline (Retry-After: 30) Linked machine(s) exist but none is online darkbloom start; darkbloom doctor for connection problems (troubleshooting)
503 model_not_loaded (Retry-After: 15) Online, but no owned machine serves this model id darkbloom start in a terminal and pick the model in its list, which downloads it if needed; darkbloom restart adds no model. List ids with the self header
503 model_capability_unsupported Machine serves the model but not this request shape (inference-enforced tool_choice without the tool-constraint advertisement, media on a text-only build) darkbloom update; load a vision-capable build
prefer requests are billed Your machine could not serve at that moment, so the fleet did Check the same causes as above; use self if you never want the fallback
Key with self_route_only returns 409/503 for every request The ceiling applies to all traffic on that key Use a different key for public routing

From a Mac that runs Darkbloom

You don't need the header there. The Mac's local API sends a request it can't take on with self (or prefer, when you chose "My Macs first") and your account key from its Keychain, so tools keep one local URL and the local key: see the local router. prefer reserves the platform price of the request up front even when one of your Macs answers (and charges nothing when one does), so a zero balance (402, type insufficient_funds) or the key's spend cap (402, type insufficient_quota) refuses it; the router then sends the request once more with self, which needs neither.

Related