---
title: "auth.md — UApiPro agent authentication"
description: "How an AI agent authenticates to the UApiPro REST API: discovery, registration, credentials, errors, and revocation."
canonical: "https://uapis.cn/auth.md"
---

# auth.md

You are an agent. This document describes how to authenticate to the UApiPro REST API (`https://uapis.cn/api/v1/`), following the section structure of the [auth.md agentic-registration profile](https://github.com/workos/auth.md): discover → pick a method → register → (claim) → exchange → use the credential → handle errors and revocation.

**Read this first — it saves you a wasted flow:** UApiPro does **not** implement the auth.md agentic-registration endpoints. There is no `agent_auth` registration surface, no `identity_endpoint`, no claim ceremony, and no ID-JAG exchange on this service, because they are not needed: UApiPro issues long-lived API keys through self-service registration, and most endpoints can be called **anonymously** without any registration at all. Every step below describes what this service actually does. Follow the steps in order; do not skip ahead.

## Step 1 — Discover

Discovery is two hops. UApiPro publishes both documents, and they are real and fetchable today.

A 401 response from the API carries a `WWW-Authenticate` header:

```http
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer realm="uapipro", error="invalid_token", error_description="Invalid or expired API key"
```

Note: the header does not carry a `resource_metadata` parameter. Use the conventional well-known paths below instead — they are stable.

### 1a. Fetch the Protected Resource Metadata

```http
GET https://uapis.cn/.well-known/oauth-protected-resource
```

Real response shape:

```json
{
  "resource": "https://uapis.cn/api/v1/",
  "authorization_servers": ["https://uapis.cn"],
  "scopes_supported": ["uapi:read", "uapi:call", "uapi:account.read", "uapi:billing.read"],
  "bearer_methods_supported": ["header"],
  "resource_documentation": "https://uapis.cn/docs/api-reference/sdks",
  "resource_name": "UApiPro REST API"
}
```

- `resource` — the canonical base URL of the API you are calling: `https://uapis.cn/api/v1/`.
- `bearer_methods_supported` — `["header"]` means you send credentials as `Authorization: Bearer …`.
- `resource_documentation` — human-and-agent-readable endpoint documentation.

### 1b. Fetch the Authorization Server metadata

```http
GET https://uapis.cn/.well-known/oauth-authorization-server
```

The document exists and publishes `issuer` (`https://uapis.cn`), `scopes_supported`, `authorization_endpoint`, `token_endpoint`, `revocation_endpoint`, and `grant_types_supported` in standard RFC 8414 shape. Two honest caveats for agents:

1. **There is no `agent_auth` block.** UApiPro does not publish `agent_auth.identity_endpoint`, `agent_auth.claim_endpoint`, or `agent_auth.events_endpoint`, because the agentic-registration ceremony is not implemented on this service. Do not POST to `/agent/identity` or `/agent/identity/claim` — those routes do not exist. Registration is self-service through a web console (Step 3) and completes in under a minute with a human in the loop exactly once.
2. **The OAuth client endpoints are not generally available.** The authorization-code and client-credentials surface referenced by the metadata is being rolled out and is not the supported path for agents today. The supported credential is the API key described below. Treat the AS metadata as forward-looking discovery, and this document as the operational truth.

The full API surface itself is machine-readable as OpenAPI 3.1 at `https://uapis.cn/openapi.json`, and the same surface is exposed as MCP tools at `https://uapis.cn/mcp` (server card: `https://uapis.cn/.well-known/mcp/server-card.json`).

## Step 2 — Pick a method

Use this decision tree — it is simpler than the auth.md profile's because the platform keys everything off one credential type:

1. **You have no user identity and only need occasional or low-cost calls** → [anonymous](#anonymous-no-registration). No registration at all. This is the closest analog of the profile's `anonymous` method, except you skip even the registration POST: 29 endpoints are permanently 0-credit, and metered endpoints debit the visitor free allowance of 1500 credits/month per public IP. Start calling immediately.
2. **You act on behalf of a user who can spend one minute in a browser once** → [API key](#api-key-the-supported-credential). The user creates a key in the console and hands it to you. This is the platform's primary and only supported credential mechanism — the practical equivalent of what `service_auth` registration would have produced, but completed by the user directly instead of through a claim ceremony.
3. **You hold an ID-JAG or a provider-minted `identity_assertion`** → stop. UApiPro does not accept `identity_assertion` registration and does not implement the `id-jag` assertion type (`urn:ietf:params:oauth:token-type:id-jag`). There is no endpoint to present it to. Fall back to method 1 or 2.

## Step 3 — Register

There is exactly one registration flow, and it is self-service:

1. The user signs in at `https://uapis.cn/login` (email verification-code sign-in; account creation is implicit on first sign-in).
2. The user opens `https://uapis.cn/console/api-keys` and creates an API key. Keys are strings with the `uapi-` prefix.
3. The user gives you the key. Treat it as a secret: store it server-side or in your secret store, never in client-side code, transcripts shown to end users, log lines, or URL query strings.

What this means for the profile's flow vocabulary:

- **No programmatic `POST /agent/identity` exists.** Do not attempt registration API calls; they will 404. The console flow above is the entire registration surface.
- **Consent is implicit and explicit at once:** the user creates the key themselves and can label it, restrict it, or delete it at any time in the same console. Because the user performs registration, there is no separate consent gate for you to surface.
- **Keys are not scoped to the OAuth scope set.** A key authenticates the account; the `uapi:*` scopes in the PRM describe the platform's permission vocabulary for the OAuth surface. Per-key restrictions (endpoint allowlists, IP allowlists) are configurable by the user in the console.
- Signed-in usage debits the account's **3500 credits/month free allowance** first, then purchased credits. Credit packs start at ¥4.9 and never expire.

If the user never registers, you can still operate anonymously within the visitor allowance — see Step 6.

## Step 4 — Claim ceremony

**Not applicable on this service.** There is no claim ceremony, no `user_code`, no `verification_uri`, and no polling grant, because registration never produces an unclaimed credential: the API key is created by the authenticated user inside their own console session, so the binding between the user and the credential exists from the moment of creation. When the user pastes the key into your configuration, the link the ceremony would have established is already complete. Proceed directly to Step 5.

## Step 5 — Exchange the assertion

**Not applicable as a separate step on this service.** There is no `identity_assertion`/`access_token` two-step exchange because the API key is itself the long-lived bearer credential — you do not exchange it, refresh it, or re-mint it. Do not POST it to any token endpoint. Skip directly to Step 6 and send it as the bearer token on every request.

Operationally this means: no token expiry to manage, no refresh flow, and no `invalid_grant` recovery path. If a call fails with 401, the problem is the key itself — see the error table below.

## Step 6 — Use the access_token

Present the API key as the bearer credential on every request:

```http
GET https://uapis.cn/api/v1/network/myip
Authorization: Bearer uapi-xxxxxxxxxxxxxxxx
```

```bash
curl "https://uapis.cn/api/v1/network/myip" \
  -H "Authorization: Bearer $UAPI_API_KEY"
```

Credential transport rules, all real and enforced:

- **Primary:** `Authorization: Bearer <key>`. Always use this form.
- **Legacy alternative:** the `X-API-Key: <key>` header is accepted for compatibility. New integrations should not use it.
- **Discouraged but functional:** a `?key=` query parameter is recognized. Do not use it unless you have no other transport — URLs leak into logs, browser history, and analytics. Never put the key in a URL shown to an end user.
- **Anonymous fallback:** if you send no credential at all, metered endpoints debit the visitor allowance (1500 credits/month per public IP) instead of failing. If you send an *invalid* credential, the request fails with 401 — it does not silently downgrade to anonymous. To fall back intentionally, drop the `Authorization` header entirely.

Metering response headers you must read before issuing the next request:

- `RateLimit-Policy` / `RateLimit` — aggregated quota/rate policy and remaining state
- `X-RateLimit-Limit` / `X-RateLimit-Remaining` — legacy single-value views
- `Retry-After` — mandatory backoff on 429

Default QPS tiers: 4 for anonymous visitors (per IP), 7 for signed-in free-allowance usage, 10/20/30 for Starter/Standard/Pro credit packs. The response headers are authoritative for a specific key and endpoint.

Full API reference: `https://uapis.cn/docs/api-reference/introduction`. Agent-specific operating guidance (error taxonomy, rate-limit etiquette, endpoint selection): `https://uapis.cn/AGENTS.md`.

## Errors

Errors on this service are JSON. The standard shape is a machine-readable string `code`, a human-readable `message` (surface it verbatim), and optional structured `details`. The support-ticket request id is in the `X-Request-ID` **response header**, not the body. A real 401 body looks like:

```json
{
  "code": "INVALID_API_KEY",
  "message": "当前 key 无效或已失效；请修正 Authorization 请求头，或删除 Authorization 请求头使用访客额度。",
  "details": {
    "api_keys_url": "https://uapis.cn/console/api-keys",
    "auth_scheme": "Bearer",
    "credential_status": "invalid_or_expired",
    "expected_header": "Authorization: Bearer <api_key>",
    "docs_url": "https://uapis.cn/docs/api-reference/introduction"
  }
}
```

Authentication-relevant failure vocabulary, mapped to the profile's error table where applicable:

| Status / code | Meaning | What to do |
| --- | --- | --- |
| 401 `INVALID_API_KEY` (with `WWW-Authenticate: Bearer realm="uapipro" error="invalid_token"`) | Key is invalid, expired, or deleted. This is the analog of the profile's `invalid_grant` — the credential itself is dead. | Do not retry. Ask the user to check or re-issue the key at `details.api_keys_url`, or drop the header to use the visitor allowance. |
| 401 `UNAUTHORIZED` / missing credential on a restricted path | Endpoint or key restriction requires authentication. | Attach a valid key and retry once. |
| 402 | Signed-in account has insufficient credits. | Surface the message verbatim; do not retry. The user can buy a credit pack or wait for the monthly allowance reset. |
| 403 | IP allowlist or key/endpoint restriction. | Surface the message verbatim; do not silently downgrade or rotate keys. |
| 429 | Rate limit, or visitor monthly quota exhausted. | Honor `Retry-After`; back off exponentially. If the visitor quota is exhausted, registration (Step 3) is the fix. |
| 400 `INVALID_PARAMETER` | Validation error in your request. | Fix the parameters; do not retry blindly. |
| 5xx (`INTERNAL_SERVER_ERROR`, `SERVICE_BUSY`) | Platform-side failure. | Retry with exponential back-off, max three attempts. |

Profile-specific codes you will **never** see from this service, because the corresponding endpoints do not exist: `anonymous_not_enabled`, `service_auth_not_enabled`, `issuer_not_enabled`, `interaction_required`, `login_required`, `invalid_claim_token`, `claimed_or_in_flight`, `claim_expired`, `authorization_pending`, `slow_down`, `expired_token`. If your generic auth.md client surfaces one of them while talking to uapis.cn, you are probing endpoints that do not exist — restart at Step 2 of this document.

Retry policy:

- 5xx → exponential backoff, retry the same request.
- 4xx → do not retry the same payload; act on the table above.
- 401 on a previously-working key → the key was deleted or rotated at the console. There is no refresh path; ask the user for a current key.

## Revocation

Two layers exist here as well, but both are simpler than the profile's:

- **Credential layer** — the user revokes a key by deleting or disabling it at `https://uapis.cn/console/api-keys`. Revocation takes effect immediately: subsequent calls with that key return 401 `INVALID_API_KEY` with `WWW-Authenticate: Bearer error="invalid_token"`. There is no agent-callable RFC 7009 revocation endpoint for API keys — key lifecycle is deliberately user-controlled through the console. If you hold a key you no longer need, simply delete it from your own storage; an unused key costs the user nothing.
- **Account layer** — if the user closes their account, every key under it dies with it. You discover this the next time a call returns 401. There is no push notification channel (`agent_auth.events_endpoint` is not implemented); treat the 401 as the revocation signal and re-run Step 3 with the user.

On a 401 for a previously-working key: do not retry the request in a loop, do not rotate to other keys you may hold for the same user, and do not fall back to anonymous mode silently if the user is paying for metered usage — surface the error, quote the `X-Request-ID` if you open a ticket at `https://uapis.cn/console/support`, and ask the user to re-issue a key.
