Skip to content
Open
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
75 changes: 61 additions & 14 deletions hpp-router/api-reference/consumer-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: HPP Router Consumer API — OpenAI-compatible endpoints, schemas, a

# API Reference

HPP Router's request and response schemas are **OpenAI-compatible**, with HPP-specific extensions for smart routing headers and prepaid quota. At a high level, you use the same patterns as the OpenAI Chat API — point your client at `https://router.hpp.io` and authenticate with your API key.
HPP Router's request and response schemas are **OpenAI-compatible**, with HPP-specific extensions for smart routing headers and wallet payments (on-chain USDC). At a high level, you use the same patterns as the OpenAI Chat API — point your client at `https://router.hpp.io` and authenticate with your API key.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

USDC → USDC.e. 요약 2) 참고.


## OpenAPI Specification

Expand All @@ -23,7 +23,8 @@ For live requests, use the [Router Playground](https://router.hpp.io/playground/
## Base URL & auth

- **Base URL:** `https://router.hpp.io`
- **Auth:** `apikey` header **or** `Authorization: Bearer <key>`. See [Authentication](../authentication).
- **Auth:** `apikey` header **or** `Authorization: Bearer <key>` for billed endpoints. `GET /llm/v1/models` does not require a key.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GET /llm/v1/models 무인증 여부 재확인 필요(요약 5). 헤더명도 X-HPP-Payment-Rail이 아니라 X-Payment-Rail입니다(요약 1).

- For x402 wallet payments, set `X-HPP-Payment-Rail: wallet` and use PAYMENT-SIGNATURE headers instead of API keys. See [Authentication](../authentication).
- **Version:** Consumer API `0.1.0`.

## Endpoints
Expand All @@ -34,7 +35,7 @@ For live requests, use the [Router Playground](https://router.hpp.io/playground/
| `GET` | `/llm/v1/models` | [List available models](#get-llmv1models) |
| `POST` | `/v1/images/generations` | [Generate images](#post-v1imagesgenerations) |
| `GET` | `/api/usage` | [Get current consumer usage](#get-apiusage) |
| `GET` | `/api/quota-check` | [Check current consumer quota](#get-apiquota-check) |
| `GET` | `/api/user/audit/:logId` | [Get user audit log](#get-apiuserauditlogid) |

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GET /api/quota-check를 표에서 삭제하고 GET /api/user/audit/:logId로 교체했는데, 실제로는 두 엔드포인트가 모두 존재합니다. 대체가 아니라 추가로 반영해 주세요. 요약 6) 참고.


---

Expand All @@ -56,20 +57,30 @@ OpenAI-compatible chat completion endpoint with HPP smart-routing headers.

Additional properties are allowed and passed through.

**Authentication:** Required. Use `apikey` header or `Authorization: Bearer <key>` for billing/usage tracking.

For x402 wallet payments, append the `X-HPP-Payment-Rail: wallet` header and sign payments using the x402 protocol.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

헤더명 오류(X-Payment-Rail). 요약 1) 참고.


**Responses:**

- `200` — `ChatCompletionResponse` (`application/json`) or an SSE stream (`text/event-stream`). Response headers include `X-HPP-Router-Resolved-Model`, `X-HPP-Router-Basket`, `X-HPP-Router-Rule-Id`, `X-HPP-Router-Rules-Version`, and `X-HPP-Router-Tier`.
- `400`, `401`, `429`, `500` — error envelope.
- `401` — Authentication required.
- `402` — Payment required (for wallet rail). Response includes `PAYMENT-REQUIRED` header with payment specifications.
- `429`, `500` — error envelope.

See [Chat Completions](../guides/chat-completions) and [Smart Routing](../smart-routing).

---

## `GET /llm/v1/models`

Lists available models (OpenAI-compatible). Each `Model` has `id`, `object` (`"model"`), `owned_by`, and an optional `pricing` object (`input`, `output`, `cache_write`, `cache_read`).
Lists available models (OpenAI-compatible). **Authentication is optional.**

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Authentication is optional" 재확인 필요. 요약 5) 참고.


Each `Model` includes `id`, `object` (`"model"`), `owned_by`, optional catalog fields (`name`, `description`, `context`, `max_output`, `tool`, `structured`, `knowledge_cutoff`, `input_modalities`, `output_modalities`), and an optional `pricing` object.

`pricing.input` / `pricing.output` / `pricing.cache_write` / `pricing.cache_read` are **USD per token** (may be `null`). For `hpprouter/auto`, `pricing` is `null` — billing uses the resolved model.

**Responses:** `200` — `ModelListResponse`; `401`, `500` — error envelope.
**Responses:** `200` — `ModelListResponse`; `500` — error envelope.

See [Models & Pricing](../models-and-pricing).

Expand Down Expand Up @@ -99,23 +110,59 @@ See [Image Generation](../guides/image-generation).

## `GET /api/usage`

Usage and quota summary for the authenticated consumer.
Usage summary for the authenticated consumer.

**Response `200`** (`UsageResponse`): `consumer_id`, `username`, `custom_id`, `quota`, `used`, `remaining`, `requests`, `total_tokens`, `total_cost`.
**Response `200`** (`UsageResponse`): `consumer_id`, `username`, `custom_id`, `requests`, `total_tokens`, `total_cost`.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UsageResponse에서 quota 관련 필드를 제거했지만 guides/quota-and-usage.mdx에 새로 추가된 spent_usdc_micro/settle_success_count/settle_failed_count는 언급되지 않았고, consumer-v1.yaml의 스키마도 여전히 quota/used/remaining을 필수로 선언하고 있어 세 곳이 서로 다릅니다. 요약 7) 참고.


**Errors:** `401`, `404`, `500`.

---

## `GET /api/quota-check`
## `GET /api/user/audit/:logId`

Get a single audit log entry for the authenticated consumer.

Access control:
- Personal consumers can only access their own logs
- Organization members can access any log from their organization's consumers

Quota availability for the authenticated consumer.
**Path params:**
- `logId` — The audit log ID (UUID)

**Response `200`** (`QuotaCheckResponse`): `has_quota`, `quota`, `used`, `remaining`.
**Query params:**
- `consumerId` — Filter by consumer (organization members only, must have access permission via `organization_members` table)

**Response `200`:**

```json
{
"id": "log-xyz",
"consumer_id": "cons-123",
"provider": "openai",
"model": "gpt-4",
"prompt_tokens": 100,
"completion_tokens": 50,
"cache_creation_input_tokens": 0,
"cache_read_input_tokens": 0,
"total_tokens": 150,
"cost": 0.002,
"status": "success",
"blockchain_tx_hash": "0x...",
"payment_rail": "wallet",
"settle_status": "settled",
"settle_amount_micro": 25000,
"scope": "organization",
"organization": {
"id": "org-abc",
"name": "My Organization",
"consumerId": "cons-org-123",
"role": "admin"
}
}
```

**Errors:** `401`, `503`, `500`.
**Errors:** `401` (not authenticated), `403` (no access to consumer), `404` (log not found), `500`.

See [Quota & Usage](../guides/quota-and-usage).
See [Usage & Activity Logs](../guides/quota-and-usage) for more details.

---

Expand Down
47 changes: 45 additions & 2 deletions hpp-router/api-reference/consumer-v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,17 @@ paths:
get:
operationId: listModels
summary: List available models
description: >
OpenAI-compatible model catalog with pricing and capability metadata.
Authentication is optional for this endpoint.
security: []

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/llm/v1/modelssecurity: []를 추가하고 401 응답을 제거했는데, 실제 Kong 설정에서 이 라우트가 key-auth로 보호되는 것이 맞다면 이 변경은 되돌려야 합니다. 요약 5) 참고.

responses:
"200":
description: OpenAI-compatible model list.
content:
application/json:
schema:
$ref: "#/components/schemas/ModelListResponse"
"401":
$ref: "#/components/responses/ErrorResponse"
"500":
$ref: "#/components/responses/ErrorResponse"
/v1/images/generations:
Expand Down Expand Up @@ -280,25 +282,66 @@ components:
const: model
owned_by:
type: string
name:
oneOf:
- type: string
- type: "null"
description:
oneOf:
- type: string
- type: "null"
pricing:
oneOf:
- $ref: "#/components/schemas/ModelPricing"
- type: "null"
context:
oneOf:
- type: number
- type: "null"
max_output:
oneOf:
- type: number
- type: "null"
tool:
oneOf:
- type: boolean
- type: "null"
structured:
oneOf:
- type: boolean
- type: "null"
knowledge_cutoff:
oneOf:
- type: string
- type: "null"
input_modalities:
type: array
items:
type: string
output_modalities:
type: array
items:
type: string
ModelPricing:
type: object
description: USD rates per token (multiply by 1_000_000 for $/1M).
properties:
input:
type: number
description: USD per input token.
output:
type: number
description: USD per output token.
cache_write:
oneOf:
- type: number
- type: "null"
description: USD per cache-write token, when applicable.
cache_read:
oneOf:
- type: number
- type: "null"
description: USD per cache-read token, when applicable.
ImageGenerationRequest:
type: object
required:
Expand Down
45 changes: 30 additions & 15 deletions hpp-router/authentication.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import CodePanel from '@site/src/components/CodePanel';

# Authentication

Every request to HPP Router must be authenticated. The gateway uses the API key to identify the **consumer**, enforce per-consumer rate limits, and check the prepaid [quota](./guides/quota-and-usage) before forwarding the request to a provider.
HPP Router uses **on-chain USDC payments** via x402 wallet. All requests require authentication with an API key for consumer identification.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

결제 토큰은 USDC가 아니라 USDC.e입니다. 요약 2) 참고.


## Getting an API key

Expand All @@ -23,11 +23,13 @@ HPP Router accepts two authentication schemes. Use whichever fits your client.

<CodePanel>
<Tabs groupId="auth-apikey" queryString>
<TabItem value="curl" label="cURL" default>
<TabItem value="curl" label="curl" default>

```bash showLineNumbers
curl https://router.hpp.io/llm/v1/models \
-H "apikey: $HPPROUTER_API_KEY"
curl https://router.hpp.io/llm/v1/chat/completions \
-H "apikey: $HPPROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"openai/gpt-5","messages":[{"role":"user","content":"Hello"}]}'
```

</TabItem>
Expand All @@ -38,11 +40,13 @@ curl https://router.hpp.io/llm/v1/models \

<CodePanel>
<Tabs groupId="auth-bearer" queryString>
<TabItem value="curl" label="cURL" default>
<TabItem value="curl" label="curl" default>

```bash showLineNumbers
curl https://router.hpp.io/llm/v1/models \
-H "Authorization: Bearer $HPPROUTER_API_KEY"
curl https://router.hpp.io/llm/v1/chat/completions \
-H "Authorization: Bearer $HPPROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"openai/gpt-5","messages":[{"role":"user","content":"Hello"}]}'
```

</TabItem>
Expand All @@ -53,15 +57,26 @@ The Bearer scheme is what most OpenAI-compatible SDKs send by default, which is

## Which endpoints require auth

All consumer endpoints are authenticated:
| Endpoint | Auth | Purpose |
| --- | --- | --- |
| `GET /llm/v1/models` | Optional | [List models](./models-and-pricing) |

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GET /llm/v1/models를 Optional로 표기했는데, kong/kong.yaml상 이 라우트에는 key-auth가 걸려 있어 실제로는 인증이 필요한 것으로 보입니다. 무인증 엔드포인트는 별도의 GET /public/v1/models입니다. 요약 5) 참고.

| `POST /llm/v1/chat/completions` | Required (wallet: also `X-HPP-Payment-Rail: wallet`) | [Chat completions](./guides/chat-completions) |
| `POST /v1/images/generations` | Required (wallet: also `X-HPP-Payment-Rail: wallet`) | [Image generation](./guides/image-generation) |
| `GET /api/usage` | Required | [Usage summary](./guides/quota-and-usage) |

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

표에서 GET /api/quota-check, GET /api/user/audit/:logId 행이 빠졌습니다. /api/quota-check는 삭제된 게 아니라 여전히 존재하는 엔드포인트입니다(src/dashboard.js). 요약 6) 참고.


| Endpoint | Purpose |
| --- | --- |
| `POST /llm/v1/chat/completions` | [Chat completions](./guides/chat-completions) |
| `GET /llm/v1/models` | [List models](./models-and-pricing) |
| `POST /v1/images/generations` | [Image generation](./guides/image-generation) |
| `GET /api/usage` | [Usage summary](./guides/quota-and-usage) |
| `GET /api/quota-check` | [Quota check](./guides/quota-and-usage) |
All requests to HPP Router require authentication with an API key. The API key identifies the consumer and is required for both wallet payments (via Kong).

For wallet payments, also include the `X-HPP-Payment-Rail: wallet` header. See [Chat Completions](./guides/chat-completions) for examples.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

헤더명이 틀렸습니다. 실제로는 X-Payment-Rail: wallet입니다. 요약 1) 참고.


## x402 Wallet

HPP Router supports **x402 Wallet** for on-chain USDC payments.

When you send a request with `X-HPP-Payment-Rail: wallet`, the gateway prompts your client to sign payment authorization using the x402 protocol. The server will respond with `PAYMENT-REQUIRED` header containing payment specifications (wallet address, amount in micro-USDC, etc.).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

같은 헤더명 오류(X-Payment-Rail)입니다. 또한 PAYMENT-REQUIRED 헤더에 지갑주소/micro-USDC 금액이 담긴다는 설명이 실제 x402 accepts 페이로드 스펙과 정확히 일치하는지 한 번 더 확인 부탁드립니다.


For detailed information about the x402 payment flow, see:
- [x402 Protocol](https://docs.x402.com)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

x402 프로토콜 링크(docs.x402.com)가 잘못되었습니다. 이 docs 저장소에 이미 HPP 전용 x402 문서(/x402)가 있으니 그쪽으로 연결해 주세요. 요약 4) 참고.

- [Wallet Payments Guide](./guides/chat-completions#wallet)

## Errors

Expand Down
16 changes: 10 additions & 6 deletions hpp-router/client-sdk/typescript.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -110,38 +110,42 @@ See [Streaming](../guides/streaming) for the streaming-fallback behavior of `hpp

## Models

`models.list()` does **not** require an API key.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

models.list()가 API 키 없이 호출 가능하다고 되어 있는데, 실제 HppRouter 생성자(packages/sdk/src/client.ts)는 apiKey가 없으면 즉시 throw합니다. 바로 아래 120행의 catalogClient 예시(apiKey 없이 생성)는 실행 시 에러가 날 것으로 보입니다.


<CodePanel>
<Tabs groupId="typescript-sdk-models" queryString>
<TabItem value="typescript" label="TypeScript" default>

```ts showLineNumbers
const models = await client.models.list();
const catalogClient = new HppRouter({
baseURL: 'https://router.hpp.io',
});

const models = await catalogClient.models.list();
console.log(models.data.data);
```

</TabItem>
</Tabs>
</CodePanel>

## Usage and quota
## Usage

<CodePanel>
<Tabs groupId="typescript-sdk-usage" queryString>
<TabItem value="typescript" label="TypeScript" default>

```ts showLineNumbers
const usage = await client.usage.get();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

client.quota.check()를 문서에서 제거했는데, 실제 SDK(packages/sdk/src/client.ts)에는 quota.check()가 그대로 남아 있습니다. wallet 결제를 쓰지 않는 경우에는 여전히 사용 가능하다는 점을 남겨두는 것이 좋을 것 같습니다.

const quota = await client.quota.check();

console.log(usage.data.remaining);
console.log(quota.data.has_quota);
console.log(usage.data);
```

</TabItem>
</Tabs>
</CodePanel>

See [Quota & Usage](../guides/quota-and-usage).
See [Usage & Settlement](../guides/quota-and-usage) for more details.

## Image generation

Expand Down
21 changes: 17 additions & 4 deletions hpp-router/guides/chat-completions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,26 @@ The chat completions endpoint is the core of HPP Router. It is OpenAI-compatible
POST https://router.hpp.io/llm/v1/chat/completions
```

## Basic request
## Payment methods

HPP Router supports **x402 Wallet** for on-chain USDC payments. Set `X-HPP-Payment-Rail: wallet` and include your API key for authentication.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

헤더명 오류. 실제로는 X-Payment-Rail: wallet입니다. 요약 1) 참고.


See [Authentication](../authentication) for details.

### Basic request (wallet)

Include both the payment rail header and your API key:

<a name="wallet"></a>

<CodePanel>
<Tabs groupId="chat-completions-request" queryString>
<TabItem value="curl" label="cURL" default>
<Tabs groupId="chat-completions-wallet" queryString>
<TabItem value="curl" label="curl" default>

```bash showLineNumbers
curl -X POST https://router.hpp.io/llm/v1/chat/completions \
-H "apikey: $HPPROUTER_API_KEY" \
-H "X-HPP-Payment-Rail: wallet" \

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curl 예시의 헤더명 오류(X-Payment-Rail). 요약 1) 참고.

-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-5",
Expand All @@ -39,6 +50,8 @@ curl -X POST https://router.hpp.io/llm/v1/chat/completions \
</Tabs>
</CodePanel>

The server will prompt for wallet payment authorization using the x402 protocol.

## Request fields

| Field | Type | Notes |
Expand Down Expand Up @@ -89,4 +102,4 @@ The `usage` block drives [billing](../models-and-pricing). When you use `hpprout

## Errors

Requests are checked against your quota before being forwarded. Insufficient quota returns **`429`**; auth failures return **`401`**. See [Errors](./errors).
Requests are checked against your wallet balance before being forwarded. Insufficient funds return **`429`**; auth failures return **`401`**. Wallet requests may also return **`402 PAYMENT REQUIRED`** with payment instructions. See [Errors](./errors).
Loading