Metadata-Version: 2.4
Name: btgamma
Version: 0.1.0
Summary: Local signing proxy for Bittensor gamma-paid subnet services
Keywords: bittensor,gamma,proxy,btauth,mcp
License-Expression: MIT
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Internet :: Proxy Servers
Requires-Dist: aiohttp==3.14.5
Requires-Dist: multidict==7.2.1
Requires-Dist: py-sr25519-bindings==0.2.4
Requires-Dist: tomlkit==0.15.2
Requires-Dist: yarl==1.25.1
Requires-Python: >=3.13
Description-Content-Type: text/markdown

# btgamma

Use any Bittensor subnet's gamma-paid service through one local URL. btgamma holds your spending
hotkey, signs each request (btauth/1) and forwards it.

Status: alpha. A signing proxy with manual top-ups; btgamma never touches your coldkey.

## Usage

Install (Python 3.13):

```console
$ uv tool install btgamma
```

Start the proxy with an unencrypted sr25519 hotkey (or set `BTGAMMA_HOTKEY_SEED` instead):

```console
$ btgamma start --hotkey ~/.bittensor/wallets/<wallet>/hotkeys/<hotkey>
btgamma http://127.0.0.1:8402  hotkey 5F…  finney
```

Point any client at a service's route. SN28 (SayGM) is OpenAI-compatible:

```console
$ OPENAI_BASE_URL=http://127.0.0.1:8402/sn/28/api/v1 OPENAI_API_KEY=unused my-agent
$ curl http://127.0.0.1:8402/sn/28/api/v1/models
```

The proxy strips the placeholder API key and signs each request with the hotkey. Open
http://127.0.0.1:8402/ for the dashboard. Other commands talk to the running daemon:
`btgamma services` (every route), `btgamma status` (deposits, credit, spends),
`btgamma topup sn28 1` (spend 1 gamma at SN28's service), `btgamma trust snN`,
`btgamma refresh`, and `btgamma config get|set` (settings in `~/.btgamma/config.toml`). Add
`--json` to any of them. To require a token from local clients, run
`btgamma config set auth.token=required` and pass `btgamma token` as the API key.

For retry-safe top-ups, add `--idempotency-key REQUEST_ID`; `POST /_gamma/topup` accepts the same
value as `idempotency_key`. A finalized spend remains `credit_pending` until the service balance
shows the credit or the configured timeout passes (default 120 seconds); set it with
`btgamma config set limits.credit_timeout=240`.

## MCP

The daemon is also an MCP server at `http://127.0.0.1:8402/_gamma/mcp` (streamable HTTP; MCP
2026-07-28, plus the `initialize`-based 2025-03-26 to 2025-11-25 for older clients). Its tools:
`list_services`, `service_details`, `status`, `spends` and `call_service`, which sends one
request through the proxy, so it is signed and paid like any other. `topup` is offered only
after `btgamma config set mcp.allow_topup=true`. Start the daemon first (`btgamma start`); every
client shares its one hotkey.

Claude Code:

```console
$ claude mcp add --transport http btgamma http://127.0.0.1:8402/_gamma/mcp
```

Cursor (`~/.cursor/mcp.json`, or `.cursor/mcp.json` in a project):

```json
{"mcpServers": {"btgamma": {"url": "http://127.0.0.1:8402/_gamma/mcp"}}}
```

Claude Desktop speaks stdio, so it runs `btgamma mcp`, a bridge that relays to the running
daemon and never loads the hotkey. In `claude_desktop_config.json` (Settings > Developer > Edit
Config), use the full path that `which btgamma` prints:

```json
{"mcpServers": {"btgamma": {"command": "/Users/you/.local/bin/btgamma", "args": ["mcp"]}}}
```

With `auth.token=required`, HTTP clients send the token as a header: add
`--header "Authorization: Bearer $(btgamma token)"` to `claude mcp add`, or
`"headers": {"Authorization": "Bearer <token>"}` in Cursor. `btgamma mcp` reads it itself.
