SpaceMIX v0.1.0 (latest)

SpaceMIX Hub models and credit

experimentalfor bothsince protocol 1

Models SpaceMIX runs itself, offered to any server with the Hub on in Settings → Models and paid per token from the server's prepaid euro credit at SpaceMIX Hub: who may use and manage them (server:hubModels, server:settings, Hub admins), top-ups, auto-recharge, the monthly cap and the hard stop, paying for a server's credit from a SpaceMIX Hub account (payers, managedInHub), the wallet a server SpaceMIX Hub hosts shares with its hosting, what a request reserves and costs, what the Hub keeps (no prompts or replies), the errors people see (hub_off among them), the server-signed requests, and the known limitations.

A SpaceMIX Hub model is a model SpaceMIX runs itself (an OpenAI-compatible endpoint on SpaceMIX's own machines, such as an Ollama model) that any SpaceMIX server can use like a model it connected itself. In Settings → Models the Hub's models are listed next to the server's own connected models, each with a name, a description and a price in euros per 1M input and output tokens. Use them when you want a model without running one or holding a provider's key. People stay free to use their own endpoints, CLI agents or the big providers instead; nothing else changes for those.

Using a Hub model costs money, paid from the server's SpaceMIX Hub credit: one prepaid balance in euros per server, shared by the whole team, topped up by card through Stripe. At zero, Hub models stop until someone tops up; every other model keeps working.

It is server and Hub surface, not part of the extension contract: extensions can't list, pick or pay for Hub models. But when the server's default model is a Hub model, an extension's host.ai.complete runs on it: the call is billed to the server's credit, works only for people with server:hubModels (for anyone else host.ai.available() is false and complete fails with the permission sentence), and fails with the credit and cap sentences in Errors. See AI. The code:

Where Files
The server apps/desktop/src-tauri/src/hub_models.rs (signing, the relay routes, the errors), ai.rs and assistant.rs (running a Hub model), auth.rs (server:hubModels)
The app apps/desktop/src/lib/hubModels.ts, src/shell/HubModelsSettings.tsx (Settings → Models). Billing is a screen on SpaceMIX Hub's own site
Signing spacemix-auth/src/server.rs (the spacemix-auth repository, shared by the Hub and the server) (hub_request_input, sign_hub_request, verify_hub_request)

This page covers what a server and an extension see.

How a request runs

  1. Someone with server:settings clicks Add on a model under SpaceMIX Hub models in Settings → Models, or in the SpaceMIX tab of the Connect a model dialog there. That saves a connected model in shell/models that names only the Hub model's id (hubModel, in apps/desktop/src/lib/models.ts); it holds no address and no key.
  2. A person with server:hubModels picks it in a chat (the model menu shows a SpaceMIX Hub badge and the price). The client sends the request to its own server (ai_chat over IPC, or POST /api/ai/chat in a browser) with only hubModel set; any baseUrl, model or apiKey it sends is ignored.
  3. The server checks server:hubModels, then sends an OpenAI chat/completions request to SPACEMIX_HUB_URL + /v1/hub-models/chat/completions, signed with its own key (see Signed requests). It never sends it to an address a client named, and doesn't follow redirects.
  4. The Hub checks the signature and the wallet, reserves the request's most possible cost, swaps in the upstream model, address and key, and passes the reply back, streamed or whole, with model renamed to the Hub model's id and system_fingerprint dropped.
  5. When the reply ends (or is cut off), the Hub charges the tokens in one ledger row and gives the reservation back.

The server-side assistant of the SpaceMIX API runs Hub models the same way, as the key's account. Clients and API callers never learn a Hub model's upstream model name, address or key: the Hub never sends them to a server.

Who may do what

Who May
Anyone signed in to the server See the catalogue (GET /api/hub-models).
server:hubModels Run Hub models in chats and through the SpaceMIX API, spending the server's credit. See the catalogue and the credit (balance, this month's usage, the cap, auto-recharge, recent usage) in Settings → Models, read-only, after Show models when no Hub model is connected; they're not shown with the Hub off.
server:settings In Settings → Models, after Show models when no Hub model is connected and not shown with the Hub off: add Hub models to the server's connected models and remove them (they are connected models, in shell/models). See the credit, top up, change auto-recharge and the monthly cap, and open Manage card (Stripe's Billing Portal). The SpaceMIX tab of Connect a model offers the same Add without Show models; opening the tab reads the catalogue. Seeing the credit doesn't need server:hubModels; running a Hub model does.
The owner Everything above: the owner holds every permission. Only the owner may ask for the credit to be paid from their own SpaceMIX Hub account (Pay for this server from your Hub account, see Paying from a SpaceMIX Hub account); no permission stands in for being the owner.
The Hub's admins Keep the catalogue and adjust any server's credit.

server:hubModels is granted like any server permission, directly or through groups in Settings → Permissions (see Who can use an extension). The seeded Members group has it: a new server's Members group starts with it, and on a server whose Members group existed before Hub models it is added once, when the server starts. Take it off the group and it stays off. The owner keeps the spending in hand with the monthly cap.

The credit

Money is integer micro-euros everywhere (1 € = 1,000,000; balanceMicro, amountMicro); prices are micro-euros per 1M tokens; the app rounds for display. The currency is fixed to euros.

Setting Default Bounds What it does
Top-up none €5 to €1000, whole cents Top up in Settings → Models (after Show models when no Hub model is connected; not shown with the Hub off): €10, €25, €100 or a custom amount. Opens Stripe Checkout, which saves the card for auto-recharge (not on a wallet managed in SpaceMIX Hub, where it is a one-off payment).
autoRecharge.enabled off Charge the saved card off-session when a usage charge leaves the balance below the threshold. Needs a card saved by an earlier top-up.
autoRecharge.thresholdMicro €5 €0 to €1000 Recharge when the balance falls below this.
autoRecharge.amountMicro €25 €5 to €1000, whole cents How much each recharge adds.
monthlyCapMicro none (null) €0 to €1,000,000 The most Hub models may cost in a calendar month (UTC, from midnight on the 1st). null clears it. Only usage counts against it, not top-ups.
  • Top-ups are credited when Stripe confirms the Checkout Session is paid, not when the person comes back. Manage card opens Stripe's Billing Portal to change or remove the card; before the first top-up there is no Stripe customer and it answers 409 Top up once first: the card is saved then.
  • Auto-recharge runs one at a time per server and at most 10 times in 24 hours. It is checked only after a usage charge. A recharge is credited when Stripe confirms it succeeded. A declined charge, one that needs the card holder to confirm it (The card needs its holder to confirm this payment. Top up by hand to confirm it.), or a disputed payment turns auto-recharge off and shows the reason as lastRechargeError (Auto-recharge didn't go through in Settings). Turning it on again clears the error. A recharge Stripe never answers stops blocking new ones after an hour.
  • The hard stop. At a balance of zero or below, every Hub model request is refused with 402 credit_exhausted until someone tops up. When this month's usage reaches the cap, they are refused with 402 monthly_cap_reached until the next month or a higher cap. Other models keep working either way. The last request before the stop may take the balance slightly below zero; nothing more runs until it's above again.
  • Refunds and disputes. A refund of a top-up or recharge takes the refunded amount off the balance. A dispute takes the disputed amount off once and turns auto-recharge off with A payment was disputed, so auto-recharge is off. Either can leave the balance below zero.

Paying from a SpaceMIX Hub account

A server's credit can be paid by a SpaceMIX ID account, its payer, instead of from the server. The payer's one card, kept on their SpaceMIX Hub account, then pays for every wallet they pay for, and its top-ups, auto-recharge, monthly limit and card are managed on Billing on SpaceMIX Hub's own site ({hub}/billing), not in Settings → Models. A server SpaceMIX Hub hosts always has a payer: the account that created it, unless it was handed on. A server you run yourself has none until its owner asks:

  1. The owner opens Settings → Models and picks Pay for this server from your Hub account. The server asks SpaceMIX Hub to let the owner's own SpaceMIX ID pay (POST /api/credit/payer); it names the account from the owner's session, never from what the client sends. The owner must have signed in to the server with that SpaceMIX ID, else the Hub refuses with 403 not_connected.
  2. The owner accepts in SpaceMIX Hub → Billing within 14 days. Until then, billing stays on the server as before.
  3. From then on the wallet uses the payer's card, with the handover settings: auto-recharge off and a monthly limit of €50, which the payer raises on the Billing page.

While a wallet has a payer, or belongs to a server SpaceMIX Hub hosts, GET /api/credit answers managedInHub: true. Settings → Models then shows the credit read-only for everyone, with Billing for this server is managed in SpaceMIX Hub and Open billing in SpaceMIX Hub. Changing auto-recharge or the cap from the server, and Manage card, are refused with 409 managed_in_hub (Billing for this server is managed in SpaceMIX Hub.). Top up from the server still works as a one-off payment that saves no card. A payer can hand the wallet to another account by email, and stop paying, on that same Billing page.

On a server SpaceMIX Hub hosts

A server the Hub created on SpaceMIX Server Cloud pays for its hosting from this same wallet, so its Hub models and its hours spend one balance. On such a server:

  • Each hour of hosting is a ledger row of kind hosting. It doesn't count against the monthly cap, which is for Hub models only, but it does lower the balance, so at zero Hub models stop with credit_exhausted too.
  • Its wallet is managed in SpaceMIX Hub: the card, auto-recharge and the monthly cap are its payer's (the account that created it, unless handed on) and are changed on SpaceMIX Hub → Billing. The server's own page on SpaceMIX Hub's site ({hub}/servers/<id>/billing) shows the trial, the hourly rate and 30 days of use, and links there for money. Only the payer (or a Hub admin) changes the settings; the owner, when someone else pays, sees them but gets 403 not_payer.
  • Top up from the server still works, but as a one-off payment: it saves no card.
  • Once the server's owner (or a Hub admin) deletes it, its wallet stops: no new auto-recharges, and every Hub model request is refused with 403 server_deleting (This server is being deleted, so it can't use Hub models.). Its last hours of hosting are still charged to the balance.

Deleting a hosted server, and what's owed:

  • The server's owner deletes it with Delete server… in its card menu in SpaceMIX Hub → Servers. Credit left in its wallet isn't refunded.
  • While the account owes for hosting (a server that's unpaid or stopped, a wallet below €0, or a server deleted while it owed), creating a billed server is refused with 402 balance_owed (Your account owes for hosting. Top up that server's credit in SpaceMIX Hub first.).
  • SpaceMIX Hub → Servers lists what's owed, each with Pay. A deleted server's debt is paid at the exact amount, rounded up to the cent and at least €0.50, as a one-off payment.
  • A Hub admin can clear what an account's deleted servers owe.

What a request costs and reserves

A request costs ceil(input × inputPrice / 1,000,000 + output × outputPrice / 1,000,000) micro-euros, rounded up once over the sum. The tokens are the ones the upstream reports in its usage. When it reports none, or the reply is cut off (the server hangs up mid-stream, the upstream breaks off), the Hub estimates about 4 bytes a token and marks the ledger row estimated. A cut-off reply is still charged for what was produced.

Before a request runs, the Hub checks what it can pay for:

  • The output is limited. A request's output is limited to the smallest of what was asked, what the credit (or what's left under the cap) still pays for after the estimated input, the model's context size, and 131,072 tokens. The input estimate counts the whole request, tools and system text included, at about 4 bytes a token. A request whose input alone uses up the credit, or that can't pay for one output token, is refused with 402 (This server's SpaceMIX Hub credit is too low for this request. Top it up to use Hub models again., or the cap's refusal).
  • Its most possible cost is reserved. That is the estimated input and the output limit at the model's prices. Reservations count against the balance and the cap for the server's next requests, so parallel requests can't spend the same credit. Each is given back once its request is charged, however it ended.
  • One choice at a time. n other than 1 is refused with 400 Hub models answer one choice at a time (`n` of 1).

Only the fields a chat request needs reach the upstream. Two servers never share a provider's prompt cache, and the upstream sees nothing of the server's own prompt_cache_key. SpaceMIX sends spacemix-chat-<chat id>, the same for every call of one chat, both from the app's own chats and from the server-side assistant.

Limit Value Past it
Hub model requests running at once, per server 8 429 too_many_in_flight
Signed catalogue and inference requests, per server 120 a minute 429 rate_limited
Signed credit requests, per server 60 a minute 429 rate_limited
Request body 8 MB 413
A reply that isn't streamed 32 MB 502 upstream_error, still charged as an estimate
One upstream request 15 minutes the request ends; a reply cut off is charged as an estimate
A ledger page 50 by default, at most 200 400

What the Hub keeps

SpaceMIX Hub never stores or logs prompts or replies. Request and reply bodies are read in memory only to find the model, the token limits and the usage counts, and are dropped with the request. The Hub keeps:

Record What
The ledger One row per balance change, append-only (updates and deletes are refused): kind (topup, usage, auto_recharge, refund, adjustment, or hosting for an hour of a hosted server), amount, balance after, and for usage the Hub model id, the input and output token counts and whether they were estimated; the Stripe object id for rows Stripe caused; the SpaceMIX ID account for an admin's adjustment; the time.
The wallet Per server: the balance, the payer's account id, the Stripe customer id and saved card's payment method id (never card numbers), the auto-recharge settings, the cap, whether a recharge is in flight, and the last recharge error.
Payers and invitations Who paid for each wallet from when until when, and the open invitations to pay for one (the account or email, who asked, when it expires).
An account's card Per account: its Stripe customer id and its one card's payment method id, brand, last 4 digits and expiry.
Moves between cards Each move of a wallet onto its payer's Stripe customer and card: old and new ids, the reason, the time.
Top-ups and recharges Per top-up and per recharge: the Stripe id, server, amount, status and time.
Stripe events handled The ids and types of Stripe events handled, for 60 days, so each counts once.
Nonces The nonces of signed requests, for 15 minutes, so none is used twice.
The catalogue The catalogue, with each model's upstream address, model name and key.

The Hub's log gets a Hub model's id with the upstream's HTTP status when it fails, and Stripe's error codes; never a body and never the upstream's address. The Hub sends the request on to the model's upstream, which runs on machines SpaceMIX sets up; what an upstream itself keeps isn't decided by this code.

On the server, the chat is saved in the person's chats as with any model. hub_models.rs logs no prompt or reply, and errors carry only the Hub's sentence and code.

Errors

What a person sees in the chat (and what /api/hub-models and /api/credit… answer as { error, code? }), from apps/desktop/src-tauri/src/hub_models.rs:

When Status Text
The Hub is off (SPACEMIX_HUB_URL=off, identity.rs): 503 hub_off from every route on this page 503 SpaceMIX Hub is turned off on this server.
Hub 402 credit_exhausted (or a 402 with no code) 402 This server's SpaceMIX Hub credit is used up. Someone who manages settings can top it up in Settings → Models.
Hub 402 monthly_cap_reached 402 This server has reached its monthly spending cap for SpaceMIX Hub models. Someone who manages settings can raise it in Settings → Models.
No server:hubModels 403 You don't have permission to use SpaceMIX Hub models on this server. Ask someone who manages members.
Hub 403 server_unknown: the server never proved its key at a SpaceMIX ID sign-in on this Hub 403 SpaceMIX Hub doesn't know this server yet. Sign in to it with a SpaceMIX ID first.
Hub 403 server_clock_skew: the server's clock is more than 5 minutes off 403 SpaceMIX Hub says this server's clock is off. Check its time.
Hub 429 too_many_in_flight 429 This server already has several SpaceMIX Hub requests running. Try again when one finishes.
Any other Hub 429 (rate_limited) 429 SpaceMIX Hub is getting too many requests from this server. Try again in a minute.
The Hub answered a redirect 502 SpaceMIX Hub redirected the request; signed requests don't follow redirects.
The Hub can't be reached 502 Couldn't reach SpaceMIX Hub: <reason>
Any other Hub error the Hub's (a Hub 5xx becomes 502) SpaceMIX Hub: <the Hub's sentence>, or SpaceMIX Hub answered <status>.
Reading the credit without server:settings or server:hubModels 403 You need the settings or SpaceMIX Hub models permission to see this server's credit.
Changing the credit without server:settings 403 Only someone who manages settings can change this server's SpaceMIX Hub credit.
Hub 409 managed_in_hub 409 Billing for this server is managed in SpaceMIX Hub.
POST /api/credit/payer by anyone but the owner 403 Only the server's owner can choose who pays for it in SpaceMIX Hub.
POST /api/credit/payer by an owner signed in without a SpaceMIX ID 409 Sign in to this server with your SpaceMIX ID first, so SpaceMIX Hub knows which account pays.
A hubModel that isn't an id in the chat That isn't a SpaceMIX Hub model id.

The Hub's own codes, which the SpaceMIX Hub: … line carries:

Code Status Means
credit_exhausted, monthly_cap_reached 402 See The credit.
unknown_model 404 No enabled Hub model with that id: There's no Hub model with that id.
upstream_rejected 400 The upstream refused the request: The Hub model refused the request (HTTP <status>). Check what it was sent.
upstream_error, upstream_unavailable 502 This Hub model isn't answering right now. Try again later.
billing_disabled 503 Credit can't be bought on this SpaceMIX Hub. This Hub doesn't take payments for credit.
stripe_error 502 Stripe couldn't do that right now. Try again later.
no_customer 409 Manage card before the first top-up.
balance_owed 402 Creating a billed hosted server while the account owes for hosting (see On a server SpaceMIX Hub hosts): Your account owes for hosting. Top up that server's credit in SpaceMIX Hub first.
server_deleting 403 A Hub model request from a server SpaceMIX Hub hosts that its owner or an admin is deleting, or has deleted: This server is being deleted, so it can't use Hub models.
managed_in_hub 409 Changing the credit's settings, or Manage card, on a wallet managed in SpaceMIX Hub. The server replaces the Hub's sentence with its own (see above).
not_connected 403 POST /api/credit/payer for an owner whose SpaceMIX ID never saved or signed in to this server: That SpaceMIX ID hasn't signed in to this server, so it can't be asked to pay for it. The app shows Sign in to this server from SpaceMIX Hub first, so it knows your account.
already_claimed 409 POST /api/credit/payer when the wallet already has a payer, or is a hosted server's: This server's wallet already has a payer; only they can hand it on, in SpaceMIX Hub.
bad_amount, bad_threshold, bad_cap, bad_return_url 400 Amounts are from €5 to €1000, in whole cents., The auto-recharge threshold is from €0 to €1000., The monthly limit is from €0 to €1,000,000., Return addresses are https (or http on localhost).
server_proof_required, server_proof_failed, server_proof_replayed 401, 403, 403 The request isn't signed, isn't signed by this server's key, or reuses a nonce.

Through the SpaceMIX API, a chat whose model is a Hub model is refused with 403 and the permission sentence before the turn starts; a Hub refusal during the turn ends it with 502 and the sentence above as error.

The server's routes

The app reaches the Hub only through its own server, which signs and relays each call (hub_call over IPC in the desktop window). The Hub's JSON comes back as it is.

Route Needs Body or query Answers
GET /api/hub-models signed in [{ id, name, description, inputPricePerMTok, outputPricePerMTok, contextTokens }], the enabled models
GET /api/credit server:settings or server:hubModels { balanceMicro, monthUsageMicro, monthlyCapMicro, autoRecharge: { enabled, thresholdMicro, amountMicro }, hasCard, lastRechargeError, rechargeInFlight, currency, billingEnabled, managedInHub }; managedInHub is true while the wallet has a payer or is a hosted server's
GET /api/credit/ledger server:settings or server:hubModels ?limit= (1 to 200, default 50), ?before= (a ledger id) { items: [{ id, kind, amountMicro, balanceAfter, modelId, inputTokens, outputTokens, estimated, accountId, createdAt }], next }, newest first; next is the before for the next page, null on the last
PATCH /api/credit/settings server:settings { autoRecharge?: { enabled?, thresholdMicro?, amountMicro? }, monthlyCapMicro?: number | null }; any other field is refused as GET /api/credit
POST /api/credit/checkout server:settings { amountMicro, returnUrl } { url }, the Stripe Checkout page. The server adds accountId, the signed-in person's SpaceMIX ID account, when they have one (never one the client sends), so the top-up's ledger row says who started it
POST /api/credit/portal server:settings { returnUrl? } or no body { url }, Stripe's Billing Portal
POST /api/credit/payer the owner none; any body is ignored { expiresAt } (Unix seconds). The server asks the Hub with the owner's own SpaceMIX ID account. The owner accepts on SpaceMIX Hub → Billing before expiresAt

returnUrl is the page Stripe sends the person back to. The app sends this page's address when the Hub would take it; on a plain-http LAN address it sends the Hub's instead, and Top up says Afterwards you land on SpaceMIX Hub, because this page isn't on https; come back here to see the balance. The server takes only an http or https address with no user name or password; the Hub then takes only https, or http on localhost or a loopback address. The Billing Portal returns to the Hub's own address when none is given.

Signed requests

Every request a server makes to Hub models or credit is signed by the server's own Ed25519 key, the key whose fingerprint is its server id. It carries the Marketplace's four headers, Spacemix-Server-Key, Spacemix-Server-Time, Spacemix-Server-Nonce and Spacemix-Server-Signature, but the signature covers the whole request: the context spacemix-server-hub-request/v1, the server id, a purpose (hub-models for the catalogue and inference, credit for the wallet), the time in Unix seconds, a fresh 64-hex nonce, the HTTP method, the path and query exactly as sent, and the SHA-256 of the body (spacemix_auth::server::hub_request_input). So a signature holds for one method, route, query and body only, and a Marketplace signature doesn't pass here.

The Hub takes the server id from the key, refuses a ?server= that names another one, a time more than 5 minutes from its own, a bad signature, a key other than the one the server proved at a SpaceMIX ID sign-in on this Hub (server_unknown), a server past its rate limit, and a nonce it has seen before. The server signs again for every send, and sends only to SPACEMIX_HUB_URL with redirects off, so its signed headers reach only the Hub.

Limitations

  • Nothing has been tested against live Stripe yet: top-ups, the card saving, auto-recharge, the Billing Portal, refunds and disputes are covered by unit tests with simulated events only.
  • A request can cost slightly more than it reserved for dense non-Latin text: the input estimate is about 4 bytes a token, and such text can have more tokens than that. The balance may then go a little further below zero.
  • Reservations are in memory on the Hub. A restart of the Hub forgets them (the requests they were for end with it).
  • A dispute the server won isn't credited back. A Hub admin adds it back.

Stability: experimental. Hub models and credit are new, the shapes and limits above may still change, and the payment flows are untested against live Stripe.

This page as markdown · All pages as one file