```yaml
product: AlterLab
title: Auth API Reference
category: api
comparison_context: "AlterLab is an alternative to Firecrawl, ScrapingBee, and Bright Data."
source_url: https://alterlab.io/docs/api/generated/auth
```

# Auth API Reference

Auto-generated API reference for auth endpoints, built from the OpenAPI spec.

## DELETE /api/v1/auth/account

Delete Account
Soft delete user account. - Password accounts: requires current password + confirm flag. - OAuth-only accounts: requires a fresh session (JWT issued within the last 5 minutes) to prevent a stolen long-lived JWT from deleting the account without any re-authentication.

Authentication: `Authorization: Bearer <session token>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `password` | body | `string` | no |  |
| `confirm` | body | `boolean` | no | Confirm |

## POST /api/v1/auth/add-password

Add Password
Add a password to an OAuth-only account. Allows users who signed up with OAuth to also have password-based login.

Authentication: `Authorization: Bearer <session token>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `password` | body | `string` | yes | Password |

## POST /api/v1/auth/change-password

Change Password
Change password for authenticated user. Requires current password for verification.

Authentication: `Authorization: Bearer <session token>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `current_password` | body | `string` | yes | Current Password |
| `new_password` | body | `string` | yes | New Password |

## POST /api/v1/auth/check-email

Check Email
Check if an email exists and if it has a password set. SECURITY: Rate limited per-IP (5/min) and per-email (10/hour) to prevent email enumeration attacks via distributed IPs.

Authentication: `X-API-Key: <your key>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `email` | body | `string` | yes | Email |

## GET /api/v1/auth/check-email-exists

Check Email Provider
Check if an email exists and what auth methods are available. Used by sign-in flow to show appropriate options. SECURITY: Rate limited to 5 requests per minute per IP to prevent email enumeration attacks. Does not reveal primary_method to reduce information leakage about user's authentication preferences.

Authentication: `X-API-Key: <your key>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `email` | query | `string` | yes |  |

## POST /api/v1/auth/complete-signup

Complete Signup
Complete signup by verifying OTP and creating the user account. This endpoint must be called after /initiate-signup to finalize account creation.

Authentication: `X-API-Key: <your key>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `email` | body | `string` | yes | Email |
| `code` | body | `string` | yes | Code |
| `device_fingerprint` | body | `object` | no | Device fingerprint data collected from client. |
| `attribution` | body | `object` | no | First-touch attribution data captured at signup. All fields are optional strings — the frontend sends whatever it has. Values are sanitized (HTML stripped, max 500 chars each). |
| `last_touch` | body | `object` | no | First-touch attribution data captured at signup. All fields are optional strings — the frontend sends whatever it has. Values are sanitized (HTML stripped, max 500 chars each). |
| `anonymous_id` | body | `string` | no |  |
| `ref_code` | body | `string` | no |  |

## POST /api/v1/auth/email-code/send

Send Email Code
Email a one-time sign-in code. The response never reveals whether the account exists. Eligible and ineligible addresses do the same request-path work (code generation, one Redis write); the email itself is sent from a background task after the response.

Authentication: `X-API-Key: <your key>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `email` | body | `string` | yes | Email |

## POST /api/v1/auth/email-code/verify

Verify Email Code
Exchange a valid emailed code for a session token (single use).

Authentication: `X-API-Key: <your key>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `email` | body | `string` | yes | Email |
| `code` | body | `string` | yes | Code |

## POST /api/v1/auth/enterprise-accept

Accept an enterprise invite and activate account
Redeems a one-time enterprise invite token. Sets the client's password, marks their email as verified, creates a session, and returns an AuthResponse so the frontend can log them in immediately. The token is deleted from Redis on success (single-use). Returns 404 if the token is not found or expired.

Authentication: `X-API-Key: <your key>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `token` | body | `string` | yes | Enterprise invite token from the magic link |
| `password` | body | `string` | yes | Password to set for the account (validated against NIST SP 800-63B rules) |
| `attribution` | body | `object` | no |  |
| `last_touch` | body | `object` | no |  |
| `anonymous_id` | body | `string` | no |  |

## GET /api/v1/auth/enterprise-invite/{token}

Look up enterprise invite metadata
Validates an enterprise invite token and returns the associated email and organisation name. Used by the /welcome/enterprise frontend page to pre-fill the activation form. No authentication required — the token is the credential. Returns 404 if the token is not found or has expired.

Authentication: `X-API-Key: <your key>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `token` | path | `string` | yes |  |

## POST /api/v1/auth/exchange-session-token

Exchange Session Token
Exchange an OTP-issued session token for full user data. Called by the NextAuth CredentialsProvider immediately after email OTP verification — the frontend receives a session_token from /verify-code and passes it here to obtain the user object needed to populate the JWT without requiring a second password entry. Security: - Session must exist in the sessions table (created by verify_code above) - Session must not have expired - Rate limited per-IP (30/min) to prevent session token enumeration, consistent with /sessions/validate

Authentication: `X-API-Key: <your key>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `session_token` | body | `string` | yes | Session Token |

## POST /api/v1/auth/forgot-password

Forgot Password
Initiate password reset flow. Sends a password reset email with a token valid for 1 hour. Always returns success to prevent email enumeration. Rate limited per-IP and per-email to prevent abuse.

Authentication: `X-API-Key: <your key>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `email` | body | `string` | yes | Email |

## GET /api/v1/auth/identity

Get Api Key Identity Endpoint
Return only the verified API-key identity for operator preflight checks. Unlike ``/me``, this endpoint does not resolve a user profile or invoke the normal spend/concurrency admission path. It is intended to be called before production probes so a stale customer key fails before any billable request.

Authentication: `X-API-Key: <your key>`

## POST /api/v1/auth/initiate-signup

Initiate Signup
Initiate signup - stores pending signup in Redis and sends OTP. The user's credentials are NOT saved to the database until they verify their email via the /complete-signup endpoint.

Authentication: `X-API-Key: <your key>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `email` | body | `string` | yes | Email |
| `password` | body | `string` | no |  |
| `name` | body | `string` | no |  |
| `device_fingerprint` | body | `object` | no | Device fingerprint data collected from client. |
| `attribution` | body | `object` | no | First-touch attribution data captured at signup. All fields are optional strings — the frontend sends whatever it has. Values are sanitized (HTML stripped, max 500 chars each). |
| `last_touch` | body | `object` | no | First-touch attribution data captured at signup. All fields are optional strings — the frontend sends whatever it has. Values are sanitized (HTML stripped, max 500 chars each). |
| `anonymous_id` | body | `string` | no |  |
| `referral_code` | body | `string` | no |  |

## GET /api/v1/auth/linked-accounts

Get Linked Accounts
Get all linked OAuth accounts for current user.

Authentication: `Authorization: Bearer <session token>`

## POST /api/v1/auth/linked-accounts/callback

Complete Link
Complete OAuth account linking after OAuth callback. Called by NextAuth callback when linking state is detected.

Authentication: `Authorization: Bearer <session token>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `state` | body | `string` | yes | State |
| `provider` | body | `string` | yes | Provider |
| `provider_account_id` | body | `string` | yes | Provider Account Id |
| `provider_email` | body | `string` | no |  |
| `display_name` | body | `string` | no |  |
| `avatar_url` | body | `string` | no |  |

## POST /api/v1/auth/linked-accounts/complete

Complete Link Public
Complete OAuth account linking (public endpoint). This endpoint is called by NextAuth's signIn callback during the account linking flow. Authentication is via the state token, not JWT. The state token identifies the user who initiated the linking request. SECURITY: Rate limited to 10 requests per minute per IP to prevent state token brute-force attacks.

Authentication: `X-API-Key: <your key>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `state` | body | `string` | yes | State |
| `provider` | body | `string` | yes | Provider |
| `provider_account_id` | body | `string` | yes | Provider Account Id |
| `provider_email` | body | `string` | no |  |
| `display_name` | body | `string` | no |  |
| `avatar_url` | body | `string` | no |  |

## POST /api/v1/auth/linked-accounts/initiate

Initiate Link
Initiate OAuth account linking flow. Generates a state token and returns the OAuth authorization URL. The frontend should redirect to this URL to start the OAuth flow.

Authentication: `Authorization: Bearer <session token>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `provider` | body | `string` | yes | Provider |

## DELETE /api/v1/auth/linked-accounts/{provider}

Unlink Account
Unlink an OAuth provider from the account. Cannot unlink the primary auth method unless another method is available. Must have at least one authentication method remaining.

Authentication: `Authorization: Bearer <session token>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `provider` | path | `string` | yes |  |

## POST /api/v1/auth/login

Login
Login with email and password. SECURITY: Rate limited per-IP (middleware, 5/15min) AND per-email (in-endpoint, 5/15min + progressive lockout at 10/hour) to prevent distributed brute-force.

Authentication: `X-API-Key: <your key>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `email` | body | `string` | yes | Email |
| `password` | body | `string` | yes | Password |

## GET /api/v1/auth/login-history

Get Login History
Get login history for current user. Returns up to `limit` most recent login attempts.

Authentication: `Authorization: Bearer <session token>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `limit` | query | `integer` | no |  |

## GET /api/v1/auth/me

Get Current User
Get current user with balance-based tier and credit information.

Authentication: `X-API-Key: <your key>`

## POST /api/v1/auth/oauth-signin

Oauth Signin
Run the OAuth sign-in and emit its ``oauth_callback_*`` funnel event (#36739).

Authentication: `X-API-Key: <your key>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `email` | body | `string` | yes | Email |
| `name` | body | `string` | no |  |
| `provider` | body | `string` | yes | Provider |
| `provider_account_id` | body | `string` | yes | Provider Account Id |
| `avatar_url` | body | `string` | no |  |
| `device_fingerprint` | body | `object` | no | Device fingerprint data collected from client. |
| `attribution` | body | `object` | no | First-touch attribution data captured at signup. All fields are optional strings — the frontend sends whatever it has. Values are sanitized (HTML stripped, max 500 chars each). |
| `last_touch` | body | `object` | no | First-touch attribution data captured at signup. All fields are optional strings — the frontend sends whatever it has. Values are sanitized (HTML stripped, max 500 chars each). |
| `anonymous_id` | body | `string` | no |  |

## POST /api/v1/auth/onboarding-event

Record Onboarding Event
Record a user onboarding lifecycle event (completed or skipped). Emits ``user.onboarding_completed`` or ``user.onboarding_skipped`` to the lifecycle service. Both are first-only events — subsequent calls for the same user are silently deduplicated. Called by the frontend after the OnboardingModal is completed or dismissed.

Authentication: `Authorization: Bearer <session token>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `event` | body | `"completed" \| "skipped"` | yes | Event |
| `at_step` | body | `integer` | no |  |

## GET /api/v1/auth/principal

Get Api Key Principal Endpoint
Resolve an API key or OAuth access token for a resource server (#31048). The hosted MCP endpoint calls this before admitting a request. Resolution is the shared ``get_current_api_key_identity`` path (API-key and OAuth caches, revocation fences), so it reserves no spend, consumes no concurrency and touches no rate state. Tool calls are billed later by the normal routes.

Authentication: `X-API-Key: <your key>`

## GET /api/v1/auth/profile

Get Profile
Get current user profile with balance-based tier and credit information.

Authentication: `Authorization: Bearer <session token>`

## PATCH /api/v1/auth/profile

Update Profile
Update user profile. Allows updating name and email. Email changes require re-verification.

Authentication: `Authorization: Bearer <session token>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `name` | body | `string` | no |  |
| `email` | body | `string` | no |  |

## POST /api/v1/auth/reset-password

Reset Password
Reset password using token from email. Validates token (hashed comparison) and sets new password. Rate limited to prevent brute-force token probing.

Authentication: `X-API-Key: <your key>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `token` | body | `string` | yes | Token |
| `new_password` | body | `string` | yes | New Password |

## GET /api/v1/auth/security-overview

Get Security Overview
Get account security overview. Returns information about authentication methods and security status.

Authentication: `Authorization: Bearer <session token>`

## POST /api/v1/auth/send-verification-code

Send Verification Code
Send verification code to user's email. SECURITY: Rate limited per-IP (5/min) and per-email (3/hour) to prevent inbox flooding and email enumeration attacks.

Authentication: `X-API-Key: <your key>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `email` | body | `string` | yes | Email |

## DELETE /api/v1/auth/sessions

Revoke All Sessions
Revoke all sessions except current one.

Authentication: `Authorization: Bearer <session token>`

## GET /api/v1/auth/sessions

Get Sessions
Get all active sessions for current user with device info.

Authentication: `Authorization: Bearer <session token>`

## GET /api/v1/auth/sessions/validate

Validate Session
Validate whether a session token is still active. Called by NextAuth jwt callback on token refresh cycles to detect revoked sessions. Does NOT require authentication — the session token itself is the credential being validated. Checks the Redis revocation list (O(1)). A revocation-store read failure is unavailable rather than falling back to session-row presence, because a present row cannot distinguish an active session from a partially completed revocation. Returns {"valid": true/false} or HTTP 503 when unavailable. Public callers are rate limited per-IP (30/min) to prevent session-token enumeration. The trusted Next.js server-to-server caller presents the existing API_INTERNAL_SECRET and receives a separate per-session budget; otherwise all administrators would share the public source-IP bucket.

Authentication: `X-API-Key: <your key>`

## DELETE /api/v1/auth/sessions/{session_id}

Revoke Session
Revoke a specific session.

Authentication: `Authorization: Bearer <session token>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `session_id` | path | `string` | yes |  |

## PATCH /api/v1/auth/sessions/{session_id}/activity

Update Session Activity
Update last activity timestamp for a session.

Authentication: `Authorization: Bearer <session token>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `session_id` | path | `string` | yes |  |

## POST /api/v1/auth/signup

Signup
Legacy signup endpoint — deprecated. This endpoint previously created accounts without OTP email verification, bypassing fraud prevention controls. Use the OTP-verified flow instead: POST /api/v1/auth/initiate-signup → POST /api/v1/auth/complete-signup See: https://github.com/RapierCraft/AlterLab/issues/533

Authentication: `X-API-Key: <your key>`

## POST /api/v1/auth/unlock-welcome-bonus

Unlock Welcome Bonus
Unlock the remaining welcome bonus after a user has made a deposit. Checks that the user has reduced_bonus metadata and has made at least one deposit. Grants the remaining bonus (full - reduced) with an idempotency key.

Authentication: `Authorization: Bearer <session token>`

## POST /api/v1/auth/verify-code

Verify Code
Verify email with code and award welcome credits.

Authentication: `X-API-Key: <your key>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `email` | body | `string` | yes | Email |
| `code` | body | `string` | yes | Code |

## POST /api/v1/auth/welcome-shown

Mark Welcome Shown
Mark welcome banner as shown for the authenticated user. This endpoint is called by the frontend after showing the welcome banner. The flag is stored server-side for cross-device consistency.

Authentication: `Authorization: Bearer <session token>`

## GET /api/v1/auth/welcome-status

Get Welcome Status
Get welcome bonus status for users with reduced bonus. Returns sibling accounts (obfuscated), payment status, and unlock eligibility. Only returns meaningful data for users with metadata.reduced_bonus = true.

Authentication: `Authorization: Bearer <session token>`
