Repository navigation
Conversation
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.
|
@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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 serviceandbittensor.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.In a terminal
listshows the services btcli can use, and--allthe ones it cannot with the reason (on mainnet today: nobtauth/1payment, a document that is not JSON, two specs where one is allowed, a hotkey missing frompublishers).showgroups the operations by the spec's tags and says who can call each:openneeds nothing,hotkeyis signed by your hotkey and paid from its balance at the service,optionalis free and signed when you have a hotkey. It also prints the exactbtcli gamma spendcommand to pay.call OPERATION --helplists the inputs with their types and descriptions from the spec, and the inputs are plain flags:A hotkey with no balance gets the service's own explanation and the command that fixes it:
A binary response (audio, video) is written to a file,
--out FILEor a temporary one, and never dropped after it was paid for.For agents and scripts
With
--jsonevery answer has one shape and every failure says what kind it is, so an agent never parses prose:show --jsonis 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).--schemasadds each operation's input JSON Schema.call --jsonprints{status, content_type, signed, body}.signedis the hotkey that signed, and so paid, ornull.--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.code:input,http(withstatusand the service's body),no_service,ambiguous,unusable,unreachable,timeout,too_largeorwallet. A call that does not fit the operation exits 2, anything else 1.--modlegives "did you mean --model?").--json,-w,-H,--out,--timeoutand--netuidare taken after the operation too, where they are usually typed.In Python
service.tool("quote-speech")is ready to hand to an agent framework, andcalltakes a tool'snameand 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, andservice.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
publisherslists the hotkey that committed its url and it has agammapayment that takesbtauth/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 thanbtauth/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.75 Hippius: launch a VM, SSH into it, then delete it.
117 EveryFrame: render an image and download it.
53 engy: a chat completion, with the balance it is paid from.
28 SayGM: a chat completion.
24 ms.computer: create a sandbox, run a command in it, delete it.
94 Cathedral: a sealed AMD SEV-SNP sandbox, a command in it, then delete it.
19 blockmachine: Bittensor JSON-RPC, paid per request.
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, shortoperationIds, tags, input descriptions). Streaming responses and non-JSON request bodies are not supported yet.