# Skill: Register with APIHub

> Obtain an API key to access the APIHub marketplace. Three paths: CLI (fastest), dashboard setup (simple), or autonomous wallet-based registration (advanced, no human needed).

## Fastest: `@apihubio/cli`

```bash
npx @apihubio/cli register
```

Opens the dashboard in your browser, walks you through signup, and saves the resulting key to `~/.apihub/config.json`. All other CLI commands (`balance`, `topup`, `call`, `install`) then work without any extra flags.

## Path A: Dashboard Setup (Recommended for human-managed agents)

The simplest way to get started. Register via the dashboard, buy credits, and generate an API key for your agent.

1. Visit https://apihub.io/agents/login
2. Enter your email to receive a magic link
3. Click the link to access the agent dashboard
4. Purchase credits from the dashboard (see the purchase-credits skill for details)
5. Click "Generate new key" (optionally add a label like "production")
6. Copy the key -- it is shown once
7. Give the API key to your agent

This is the recommended path for most users. You control the wallet, manage credits, and can revoke or rotate keys at any time from the dashboard.

## Path B: Autonomous Registration (Advanced)

For fully autonomous agents that have their own funded EVM wallets. No email, no dashboard, no human in the loop.

### Prerequisites

- An EVM wallet (private key or signer) on Base (chain ID 8453)
- Ability to call personal_sign (ethers, viem, or raw JSON-RPC)
- A funded wallet to purchase credits autonomously

### Step 1: Get the challenge

```
GET https://api.apihub.io/v1/register/challenge
```

Response:
```json
{
  "ok": true,
  "data": {
    "message": "Sign this message to register with APIHub.\n\nThis signature proves you control this wallet.\n\nTimestamp: 1713700000"
  }
}
```

### Step 2: Sign the challenge

Sign the message with your wallet using personal_sign (EIP-191).

With viem:
```typescript
import { createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { base } from "viem/chains";

const account = privateKeyToAccount("0xYOUR_PRIVATE_KEY");
const client = createWalletClient({ account, chain: base, transport: http() });
const signature = await client.signMessage({ message: challenge.data.message });
```

With ethers:
```typescript
const wallet = new ethers.Wallet("0xYOUR_PRIVATE_KEY");
const signature = await wallet.signMessage(challenge.data.message);
```

### Step 3: Submit registration

```
POST https://api.apihub.io/v1/register
Content-Type: application/json

{
  "wallet_address": "0xYourWalletAddress",
  "signature": "0xTheSignatureFromStep2"
}
```

Response:
```json
{
  "ok": true,
  "data": {
    "agent_id": "01ABC...",
    "api_key": "ahk_7Kx9mQ3bRtN5wPqYjL2sFhDc8eAv4G6X",
    "api_key_prefix": "ahk_7Kx9mQ3b"
  }
}
```

**Store the api_key immediately.** It is shown once and cannot be recovered (only the hash is stored).

### Step 4: Verify it works

```
GET https://api.apihub.io/v1/wallet/balance
Authorization: Bearer ahk_7Kx9mQ3bRtN5wPqYjL2sFhDc8eAv4G6X
```

## What to do next

- Purchase credits: https://apihub.io/skills/purchase-credits.md
- Make your first API call: https://apihub.io/skills/make-api-call.md
- Connect via MCP: https://apihub.io/skills/use-mcp.md

## Error codes

| Code | Meaning |
|------|---------|
| INVALID_SIGNATURE | Signature does not match the wallet address |
| CHALLENGE_EXPIRED | Challenge older than 15 minutes -- request a new one |
| WALLET_ALREADY_REGISTERED | This wallet already has an account -- use the existing key |
