Skip to content

Latest commit

 

History

History
94 lines (72 loc) · 2.08 KB

File metadata and controls

94 lines (72 loc) · 2.08 KB

Getting Started with P402

1. Get an API Key

  1. Sign up at p402.io
  2. Go to Dashboard → Settings → API Keys
  3. Click Generate Key — copy it immediately (shown once)
  4. Set it as an environment variable:
export P402_API_KEY=p402_live_...

2. Make Your First Request

curl -X POST https://p402.io/api/v2/chat/completions \
  -H "Authorization: Bearer $P402_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [{ "role": "user", "content": "Hello from P402!" }],
    "p402": { "mode": "cost" }
  }'

You'll get back an OpenAI-compatible response plus p402_metadata:

{
  "choices": [{ "message": { "role": "assistant", "content": "Hello! ..." } }],
  "p402_metadata": {
    "provider": "deepseek",
    "model": "deepseek-chat",
    "cost_usd": 0.000089,
    "latency_ms": 312,
    "cached": false
  }
}

3. Install the SDK

npm install @p402/sdk viem
import P402Client from '@p402/sdk';

const p402 = new P402Client({ apiKey: process.env.P402_API_KEY });
const res = await p402.chat({
  messages: [{ role: 'user', content: 'Hello!' }],
  p402: { mode: 'balanced' }
});

4. Install the CLI

npx p402 login     # Prompts for your API key
npx p402 chat "Hello!"
npx p402 health

5. Explore

What Where
Dashboard p402.io/dashboard
Models + pricing npx p402 models list or /api/v2/models
Routing guide docs/routing-guide.md
Session budgets docs/sessions.md
x402 payments docs/x402-payments.md
A2A protocol docs/a2a-protocol.md
Full examples examples/

Base URL

https://p402.io

All API versions are stable. No beta prefixes.

Authentication

All authenticated endpoints require:

Authorization: Bearer p402_live_...

Public endpoints (health, supported, models) do not require authentication.

Authentication guide