Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"version": "0.2",
"language": "en",
"words": [
"opencode",
"xdragon",
"ZGPC",
"deeplinking",
"lottielab",
"okxwallet",
Expand Down
2 changes: 1 addition & 1 deletion docs/ai-context.md
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ response = client.chat.completions.create(
)
```

**Router also supports**: image generation via `POST /v1/images/generations` (OpenAI-compatible, sync) or `POST /v1/async/images/generations` + `GET /v1/async/jobs/{jobId}?provider_address=...` (recommended for production) — both paths must pass `"response_format": "b64_json"` today; URL responses will be added later. Also `/v1/audio/transcriptions`, provider routing via `X-0G-Provider-*` request headers (`X-0G-Provider-Sort: latency`/`price`, `X-0G-Provider-Address: 0x…` to pin, or `X-0G-Provider-Max-Price-Usd-Prompt`/`-Completion`/`-Image` to cap per-request price — header-only, malformed values return `400`), `GET /v1/models` (no auth), `GET /v1/account/balance`, `GET /v1/account/usage/{stats,history}`. The Router also serves the **Anthropic Messages API** (`POST /v1/messages`): set `ANTHROPIC_BASE_URL=https://router-api.0g.ai` to point Anthropic SDKs or Claude Code at it; models listing `"anthropic"` in `supported_formats` on `GET /v1/models` support this format.
**Router also supports**: image generation via `POST /v1/images/generations` (OpenAI-compatible, sync) or `POST /v1/async/images/generations` + `GET /v1/async/jobs/{jobId}?provider_address=...` (recommended for production) — both paths must pass `"response_format": "b64_json"` today; URL responses will be added later. Also `/v1/audio/transcriptions`, provider routing via `X-0G-Provider-*` request headers (`X-0G-Provider-Sort: latency`/`price`, `X-0G-Provider-Address: 0x…` to pin, or `X-0G-Provider-Max-Price-Usd-Prompt`/`-Completion`/`-Image` to cap per-request price — header-only, malformed values return `400`), `GET /v1/models` (no auth), `GET /v1/account/balance`, `GET /v1/account/usage/{stats,history}`. The Router also serves the **Anthropic Messages API** (`POST /v1/messages`): set `ANTHROPIC_BASE_URL=https://router-api.0g.ai` to point Anthropic SDKs or Claude Code at it; models listing `"anthropic"` in `supported_formats` on `GET /v1/models` support this format. To configure coding tools (Claude Code, OpenCode V1, Pi, Hermes Agent) without editing config by hand, use the `0gpc` CLI ([npm: `@0gfoundation/0gpc`](https://www.npmjs.com/package/@0gfoundation/0gpc)): `npx @0gfoundation/0gpc@latest` (Node.js 22+, macOS/Linux) — see [0gpc CLI](/developer-hub/building-on-0g/compute-network/router/clients/0gpc-cli).

**Quick Start — Direct (SDK)**:

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
---
id: 0gpc-cli
title: 0gpc CLI
sidebar_position: 0
description: "Connect Claude Code, OpenCode, Pi, or Hermes Agent to the 0G Compute Router with one command — preview every change, undo any time."
keywords: [0gpc, CLI, Claude Code, OpenCode, Pi, Hermes Agent, 0G Private Computer, Router, coding tools]
---

# Introducing the 0gpc CLI

> Use [0G Private Computer](https://pc.0g.ai) in the coding tools you already have. It takes one command and a few steps, and you can undo it any time.

---

## Why we built it

Connecting 0G models to your coding tools used to mean editing config files by hand, and that came with a few headaches:

- Every tool is set up differently, so each new tool means figuring it out all over again.
- One small detail off and it stops working, often without telling you what went wrong.
- Editing config by hand can easily break your existing settings, and by the time you want to undo it, you may not remember what was there before.
- Your API key gets pasted all over the place and can easily end up somewhere it shouldn't.

With 0gpc, you pick a tool and a model and enter your key once. 0gpc writes the configuration, shows you each change before saving it, and can undo it later.

---

## What it does

0gpc currently supports four coding tools:

| Tool | Notes |
|---|---|
| Claude Code | Project and user scope |
| OpenCode V1 | Project and user scope; OpenCode V2 is not supported yet |
| Pi | User scope only |
| Hermes Agent | User scope only; default profile only |

### Set up

The first time you run `0gpc`, a guided setup starts:

1. **Environment check**: finds which tools are installed and whether they are recent enough. For a missing tool, 0gpc shows the official install command and guide link. **It only shows them; it never runs them for you.**
2. **Key input**: your key is hidden as you type it. You can also pipe it in with `--stdin`.
3. **Model selection**: loads the Router's model catalog and shows each model's provider, context length and capabilities. Models that are not compatible with the tool are filtered out. If the catalog does not provide a field, 0gpc shows it as unknown instead of making up a value.
4. **Change preview**: lists every file to be written and every field to be changed, Nothing is written until you confirm.
5. **Optional verification**: you decide whether to send one minimal request to verify your key (this may cost a very small amount). After verification, you can launch the tool directly.

You can connect several tools in one setup: enter your key once, choose a model for each tool, and review one combined preview. Results are reported separately for each tool.

### Switch

Run `0gpc` again after setup to open the management menu, where you can:

- **Change models**: pick a different compatible model for a connected tool.
- **Add or disconnect tools**: connect a new tool, or disconnect one. Disconnecting removes only the settings 0gpc added.
- **Replace your key**: after you replace a key, every tool using it is updated automatically.
- **View history and undo**: see what has changed and undo the latest change. If you edited that setting yourself, 0gpc first shows you what it wrote, what's there now and what it will restore, then asks you to confirm.

### Diagnose

- **Check connections**: see which tools are connected and which model each one uses, and list the models you can choose from.
- **Local check**: without going online, checks whether your setup is complete or has been changed, and tells you what to do next.
- **Online check**: confirms that your key works and that you have enough balance. If something's wrong, it tells you whether the key is invalid, your balance is too low, you don't have permission, or the model can't be found.
- **Proxy hint**: if you're behind a proxy and can't connect, it tells you how to fix it, without showing your proxy address.

---

## Installation

0gpc is published on npm as [`@0gfoundation/0gpc`](https://www.npmjs.com/package/@0gfoundation/0gpc).

**Requirements:**

1. macOS or Linux
2. Node.js 22 or later ([download Node.js](https://nodejs.org/en/download/); with nvm: `nvm install 22 && nvm use 22`)
3. At least one supported coding tool
4. A 0G API key: [pc.0g.ai/dashboard/api-keys](https://pc.0g.ai/dashboard/api-keys)

**Option 1: run without installing**

```sh
npx @0gfoundation/0gpc@latest
```

**Option 2: install globally (for the shorter `0gpc` command)**

```sh
# Install or upgrade
npm install -g @0gfoundation/0gpc@latest

# Start in your project directory
0gpc
```

Use **↑ / ↓** to move, **Enter** to confirm and **Ctrl-C** to cancel.

> Migrating from the old package `@0xdragon888/0gpc`: run `npm uninstall -g @0xdragon888/0gpc` first, then install the new package. Your configuration and key are kept, so you do not need to connect again.

---

## Command list

The examples below use the global `0gpc` command. Without a global install, replace it with `npx @0gfoundation/0gpc@latest`.

```sh
# Help / version
0gpc -h
0gpc -v

# First-time setup, or manage existing connections
0gpc

# API key management
0gpc key set # Save or replace a key using hidden input
0gpc key set --stdin # Read a key from piped standard input
0gpc key rm # Remove an unused saved key

# Show connections
0gpc status
0gpc status --json # Machine-readable output

# Health checks
0gpc doctor --offline # Check local configuration
0gpc doctor --offline --strict # Fail on warnings as well as errors
0gpc doctor --network # Verify access; may incur a charge

# Preview configuration (run from your project root)
0gpc apply claude --scope project --model <model-id> --dry-run

# Save configuration
0gpc apply claude --scope project --model <model-id> --yes

# Disconnect a tool; keep the saved key
0gpc reset claude --yes
```

- Tool IDs: `claude`, `opencode`, `pi`, `hermes`
- Scopes: `project` or `user`; Pi and Hermes support `user` only

**File locations:**

| Default path | Contents |
|---|---|
| `~/.config/0gpc/config.toml` | Connections and preferences |
| `~/.local/share/0gpc/keys/` | Saved API keys |
| `~/.local/state/0gpc/` | Change records and backups |

XDG paths are supported, and `ZGPC_HOME` sets a custom storage location.

| Tool | Configuration files 0gpc writes |
|---|---|
| Claude Code | Project: `.claude/settings.local.json`; user: `~/.claude/settings.json` |
| OpenCode V1 | Project: `opencode.json` or `opencode.jsonc`; user: under `~/.config/opencode/` |
| Pi | `~/.pi/agent/models.json` and `~/.pi/agent/settings.json` |
| Hermes Agent | `~/.hermes/config.yaml` and `~/.hermes/.env` |

---

## What this means

You don't need to learn four config formats to try 0G's private inference. Going from an API key to a 0G model in Claude Code usually takes a few minutes.

Your existing setup stays yours. 0gpc only touches the fields it writes, shows them to you before saving, and can put back what was there before.

Teams can script the same setup with `apply --dry-run`, JSON output and fixed exit codes, whether that's in CI or in onboarding for new hires.

Your key lives in one place and never shows up in logs, terminal output or JSON. Nothing that costs money happens without your say-so, and 0gpc sends no telemetry and never updates or installs anything on its own.

A tool should save you time, not make more work. That's the one thing 0gpc is for.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ description: "Configure Claude Code to run on the 0G Compute Router."
[Claude Code](https://code.claude.com/docs) reaches the Router over the Anthropic Messages
API, so it needs configuration only — no plugin, no proxy.

:::tip Skip the manual setup
[0gpc](./0gpc-cli) writes this configuration for you, previews every change, and can undo it.
:::

## Configure

Create `~/.claude/settings.json` (Windows: `C:\Users\<username>\.claude\settings.json`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,6 @@ That's it. You're talking to a decentralized TEE-backed provider through an Open

- **[Chat Completions](./features/chat-completions)** — streaming, tool calling, system prompts
- **[Provider Routing](./routing)** — route by latency, price, or specific provider
- **[0gpc CLI](./clients/0gpc-cli)** — connect Claude Code, OpenCode, Pi, or Hermes Agent with one command, no hand-edited config
- **[Claude Code](./clients/claude-code)** — point Claude Code at the Router, including auto mode's permission gate
- **[Models](./models)** — browse the catalog with live pricing
1 change: 1 addition & 0 deletions sidebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ const sidebars: SidebarsConfig = {
'Point an existing client or coding tool at the Router — configuration only, no SDK changes.',
},
items: [
'developer-hub/building-on-0g/compute-network/router/clients/0gpc-cli',
'developer-hub/building-on-0g/compute-network/router/clients/claude-code',
],
},
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/llms-txt-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,10 @@ module.exports = function llmsTxtPlugin(context, options = {}) {
k = j + 1;
while (k < lines.length && lines[k].trim() === '') k += 1;
}
const following = (lines[k] || '').trim();
// Skip any other H1 or opening blockquote the same way
// firstBodyLine does, so a page whose H1 differs from its title
// still matches.
const following = firstBodyLine(lines.slice(k, k + 50).join('\n'));
const match = candidates.get(m[1]).find((c) => !used.has(c.doc.id) && c.firstLine && following.startsWith(c.firstLine.slice(0, 60)));
if (!match) continue;
used.add(match.doc.id);
Expand Down
Loading