---
title: "Auth keys API: trade a PKCE code for a scoped key"
description: "Finish app sign-in with OAuth 2.0 PKCE: exchange the approved code and your verifier for a new API key with the label and USD budget the user accepted."
canonical: https://pentestllm.ai/docs/auth-keys
generated: 2026-11-27T06:25:48.447Z
source: https://pentestllm.ai/docs/auth-keys
base_url: https://api.pentestllm.ai/v1
---

[Docs](https://pentestllm.ai/docs) / API reference

# App sign-in keys API

Updated 2026-11-22. Published by PentestLLM.

A tool your analysts install can get its own key without anyone pasting one: the user approves a label and a budget in the browser, and the tool exchanges the returned code at `https://api.pentestllm.ai/v1` for a key owned by their organization.

## Route

| Route | Statuses |
| --- | --- |
| `POST /v1/auth/keys` | 200, 400, 403, 409 |

The last step of OAuth 2.0 with PKCE. It takes no key itself and answers any origin; the key it mints is an ordinary one, scoped by the label and budget the user accepted.

## The flow

| Step | What happens |
| --- | --- |
| `1` | Open https://app.pentestllm.ai/auth in the browser with callback_url, code_challenge and code_challenge_method=S256; key_label, limit (USD) and state are optional. |
| `2` | The user signs in and approves the label and budget shown. |
| `3` | The browser lands on your callback with ?code= appended. |
| `4` | Your app posts the code and its verifier to this route and stores the key it gets back. |

## Body

| Field | Type | Notes |
| --- | --- | --- |
| `code` | string, required | The code from the callback URL. |
| `code_verifier` | string, required | 43 to 128 characters of A-Z, a-z, 0-9 and -._~ whose S256 hash was the code_challenge. |
| `code_challenge_method` | string | S256. |
| `callback_url` | string | Optional; when sent it must be the approved callback exactly. |

## Answer

| Field | Meaning |
| --- | --- |
| `key` | The new key, shown this once. Store it now. |
| `key_id` | Its id, for the keys API and the console. |
| `name` | The key_label the user approved. |
| `limit_usd` | Its prepaid budget in dollars, or null for none. |

## Errors

| Status | Code | When |
| --- | --- | --- |
| `400` | invalid_grant | The code is invalid, expired or already used, the verifier does not match, or callback_url is not the approved one. invalid_request and invalid_code_challenge_method share the status. |
| `403` | key_unavailable | New keys are switched off for that account. |
| `409` | limit_reached | The organization already holds 50 active keys. |

## Example

```bash
curl https://api.pentestllm.ai/v1/auth/keys \
  -H "Content-Type: application/json" \
  -d '{"code": "<code from the callback>", "code_verifier": "<your verifier>", "code_challenge_method": "S256"}'
```

## Questions

### Why a verifier instead of a client secret?

A desktop tool or a CI step cannot keep a secret. With PKCE only the S256 hash travels up front and the verifier stays on the machine, so a code picked off a redirect is worthless without it.

### Which callbacks are allowed?

An https URL, or plain http on localhost, 127.0.0.1 or [::1] for a tool that listens on the machine itself. The approved URL is pinned, and a different callback_url at exchange time fails with invalid_grant.

### How long do I have, and can I retry?

Ten minutes from approval, and one attempt: the first exchange spends the code whether or not the verifier matched. A retry needs a fresh approval.

## Read next

- [MCP servers](https://pentestllm.ai/docs/mcp-servers)
- [Log export](https://pentestllm.ai/docs/exports)
- [Invoices](https://pentestllm.ai/docs/invoices)
- [Billing details](https://pentestllm.ai/docs/billing-details)
- [Statement signing key](https://pentestllm.ai/docs/statements-public-key)
- [Keys and scopes](https://pentestllm.ai/docs/keys)
- [Usage and signed receipts](https://pentestllm.ai/docs/usage-and-receipts)
- [Spend limits and balance](https://pentestllm.ai/docs/spend-limits)
- [Redaction and guardrails](https://pentestllm.ai/docs/redaction-and-guardrails)
- [Sessions](https://pentestllm.ai/docs/sessions)
- [Embeddings, rerank and moderation](https://pentestllm.ai/docs/retrieval-and-moderation)
- [Batch files](https://pentestllm.ai/docs/files)
- [Batches](https://pentestllm.ai/docs/batches)
- [Status and proof feeds](https://pentestllm.ai/docs/status-and-proof)
- [Count tokens](https://pentestllm.ai/docs/count-tokens)
- [Usage by app](https://pentestllm.ai/docs/stats-apps)
- [Webhook deliveries](https://pentestllm.ai/docs/webhooks-deliveries)
- [Docs: connect in two minutes](https://pentestllm.ai/docs)
