Skip to content

Add btcli service and bittensor.services - #3370

Draft
mcjkula wants to merge 7 commits into
RaoFoundation:release-498from
mcjkula:feat/subnet-services
Draft

mcjkula wants to merge 7 commits into
RaoFoundation:release-498from
mcjkula:feat/subnet-services

Conversation

@mcjkula

@mcjkula mcjkula commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Description

Subnets publish paid HTTP services with gamma: a hotkey commits a services document, the document names an OpenAPI 3 spec, and callers pay by spending gamma at the service hotkey and signing each request with btauth/1. Until now each caller wrote that client by hand. This adds one, btcli service and bittensor.services: it reads the chain, the document and the spec, and turns every operation into a command and a tool definition, so a service is used without reading its docs or writing a request.

btcli service list                                   # what you can use
btcli service show --netuid 117                      # one service and its operations
btcli service call --netuid 117 quote-speech --model eleven-v4-turbo --text 'Hello'

In a terminal

btcli service in a terminal

list shows the services btcli can use, and --all the ones it cannot with the reason (on mainnet today: no btauth/1 payment, a document that is not JSON, two specs where one is allowed, a hotkey missing from publishers). show groups the operations by the spec's tags and says who can call each: open needs nothing, hotkey is signed by your hotkey and paid from its balance at the service, optional is free and signed when you have a hotkey. It also prints the exact btcli gamma spend command to pay. call OPERATION --help lists the inputs with their types and descriptions from the spec, and the inputs are plain flags:

$ btcli service call --netuid 117 quote-speech --model eleven-v4-turbo --text 'Hello from subnet services' -w demo -H demo
             model  eleven-v4-turbo
        characters  26
               usd  0.002
        balanceUsd  0
  gamma.spendGamma  0.1
     gamma.command  btcli gamma spend --netuid 117 --service-hotkey 5G9K4zDrdcAE8F1MaaZNxLGXuhMApR5ENZGTs2wAEhiptHEf --amount-gamma 0.1

A hotkey with no balance gets the service's own explanation and the command that fixes it:

$ btcli service call --netuid 117 get-key -w demo -H demo
error: HTTP 402 from EveryFrame
  note: this hotkey has no balance. Sign POST /render/quote (or /speech/quote) with it to get the Gamma to spend ...
  help: pay the service with btcli gamma spend --netuid 117 --service-hotkey 5G9K4zDr...hiptHEf --amount-gamma AMOUNT -w demo -H demo

A binary response (audio, video) is written to a file, --out FILE or a temporary one, and never dropped after it was paid for.

For agents and scripts

btcli service with --json

With --json every answer has one shape and every failure says what kind it is, so an agent never parses prose:

  • show --json is a compact index: each operation's name, auth, method, summary and the names of its required and optional inputs (1.4 KB for subnet 19, 76 KB for Lium's 217 operations). --schemas adds each operation's input JSON Schema.
  • call --json prints {status, content_type, signed, body}. signed is the hotkey that signed, and so paid, or null.
  • --inputs '{"model": "eleven-v4-turbo", "text": "Hello"}' passes all inputs as one object, also from a file (@inputs.json) or stdin (@-); flags add to it.
  • An error is JSON on stderr with a code: input, http (with status and the service's body), no_service, ambiguous, unusable, unreachable, timeout, too_large or wallet. A call that does not fit the operation exits 2, anything else 1.
  • A misspelled input suggests the right one (--modle gives "did you mean --model?").
  • --json, -w, -H, --out, --timeout and --netuid are taken after the operation too, where they are usually typed.
$ btcli --json service call --netuid 117 quote-speech --inputs '{"model": "eleven-v4-turbo", "text": "Hello"}' -w demo -H demo
{
  "status": 200,
  "content_type": "application/json",
  "signed": "5FF9W6SMsFWXSzPBojC8GBTfWCNYWBQ5wJtNYgzm5AXyD29x",
  "body": {"model": "eleven-v4-turbo", "characters": 5, "usd": 0.002, "balanceUsd": 0, "gamma": {...}}
}

In Python

async with bt.Subtensor("finney") as client:
    service = await bt.services.load(client, netuid=117)
    tools = service.tools()  # one {name, description, input_schema} per operation

    signer = await bt.http_auth.prepare_signer(wallet, client=client)
    quote = await service.call(
        "quote-speech", {"model": "eleven-v4-turbo", "text": "Hello"}, signer=signer
    )
    quote.raise_for_status()
    print(quote.json()["usd"])  # 0.002

service.tool("quote-speech") is ready to hand to an agent framework, and call takes a tool's name and inputs back:

{
  "name": "quote-speech",
  "description": "Price a speech request.",
  "input_schema": {
    "type": "object",
    "properties": {
      "model": {"type": "string", "description": "A models[].id from GET /speech/models."},
      "text": {"type": "string", "description": "Up to models[].maxChars characters."},
      "voice": {"type": "string", "description": "A voices[].id from GET /speech/models."},
      "language": {"type": "string", "description": "A languages[].id from GET /speech/models; omit for auto."}
    },
    "required": ["model", "text"]
  }
}

bt.services.discover(client) returns every published service with the reason any is unusable, load_url(url) reads a document before it is published, and service.balance(signer=...) reads what a hotkey can still spend.

How a service is trusted

The client trusts only the chain. It uses a document only if the document's publishers lists the hotkey that committed its url and it has a gamma payment that takes btauth/1. Each request is signed with the service hotkey as the receiver, so another service cannot replay it, and the signature binds the target and the body. Requests go only to https urls on public hosts (http and this machine too on a local chain), signed requests are never redirected, and each request has one deadline over DNS, connect, TLS and the read. A spec that is not OpenAPI 3, and operations it cannot call (non-JSON bodies, credentials other than btauth/1, colliding input names), are listed as not offered with the reason instead of failing at call time.

Mainnet

All 8 subnets whitelisted for gamma emission work: 19 blockmachine, 24 ms.computer, 28 SayGM, 51 Lium, 53 engy, 75 Hippius, 94 Cathedral and 117 EveryFrame. The examples above ran against mainnet with a new, unfunded demo wallet. The recordings below are real paid calls on each of them, with gamma minted and spent at the service first.

51 Lium: rent a GPU, SSH into it and run nvidia-smi, then delete the pod.

lium

75 Hippius: launch a VM, SSH into it, then delete it.

hippius

117 EveryFrame: render an image and download it.

everyframe

53 engy: a chat completion, with the balance it is paid from.

engy

28 SayGM: a chat completion.

saygm

24 ms.computer: create a sandbox, run a command in it, delete it.

mscomputer

94 Cathedral: a sealed AMD SEV-SNP sandbox, a command in it, then delete it.

cathedral

19 blockmachine: Bittensor JSON-RPC, paid per request.

blockmachine

The guide is docs/guides/services.mdx; it also says what a publisher can add to the spec to make a service nicer to use (security: [] on free operations, short operationIds, tags, input descriptions). Streaming responses and non-JSON request bodies are not supported yet.

Find, show and call the services subnets publish with gamma: the client reads the services document and its OpenAPI 3 spec and signs requests with btauth/1.
@vercel

vercel Bot commented Nov 26, 2026

Copy link
Copy Markdown

@mcjkula is attempting to deploy a commit to the RaoFoundation Team on Vercel.

A member of the Team first needs to authorize it.

service list shows the services btcli can use and moves the rest, with a short reason, behind --all. Column lists no longer wrap past the terminal, suggested commands name only a wallet that was given, and -w, -H and --wallet-path work after the operation like --json.
A validator can publish a service under any name, so --netuid now means the owner's and list and show say which one published it. Tool definitions and service metadata lose control and invisible characters, and a service's error text is attributed to it.
btcli keeps them ten minutes and signs with an ordinary hotkey without
the chain, so a run of calls is not rate-limited by the endpoint. An
answer of several lines keeps them, and the pay hint names --network.
A spec can be megabytes: Hippius's is 3 MB and took up to 35 s, so a
run of calls downloaded it each time and often hit the 20 s timeout.
Documents and specs now ask for gzip, a spec gets the 60 s of a call,
and btcli keeps both as long as their max-age says, ten minutes at most.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant