> ## Documentation Index
> Fetch the complete documentation index at: https://docs.anotherwrapper.com/llms.txt
> Use this file to discover all available pages before exploring further.

# API Overview

> Understand the main route groups and patterns used by the backend

<Info>
  AnotherWrapper mostly uses App Router route handlers. Many "API features" don't live in one central `/api` folder -- app-specific routes live **right next to the app** that owns them.
</Info>

## Two Main API Areas

### Shared API Routes (`app/api/*`)

These are routes used across the whole product:

* Better Auth handler and provider callbacks
* Avatar uploads
* OG image generation
* Payment webhooks

### App-Specific API Routes

These live inside the product apps themselves, keeping logic close to the UI it belongs to:

* `app/(apps)/chat/api/*`
* `app/(apps)/image-studio/api/*`
* `app/(apps)/video-studio/api/*`
* `app/(apps)/voice/api/*`
* `app/(apps)/audio/api/*`
* `app/(apps)/vision/api/*`
* `app/(apps)/marketing-plan/api/*`
* `app/(apps)/launch-simulator/api/*`

<Tip>
  Good rule of thumb: if a route is tightly tied to one app's UX, keep it in that app's folder. If it's shared across the whole product, it belongs under `app/api`.
</Tip>

## Common Backend Patterns

<AccordionGroup>
  <Accordion title="Auth-first route protection">
    Many routes use helpers like `requireApiUser()` so protected actions fail fast if the user isn't logged in. No guessing, no silent failures.
  </Accordion>

  <Accordion title="Credit reservation and refund">
    AI generation routes typically follow this pattern:

    1. Authenticate the user
    2. Reserve credits
    3. Call the AI provider
    4. Store the result
    5. Refund credits if the generation fails

    This pattern shows up across multiple AI app routes and keeps your credit system reliable.
  </Accordion>

  <Accordion title="Provider abstraction">
    The backend doesn't hardcode one provider flow per page. Instead, it routes through shared model/provider helpers. This means you can swap models without rewriting routes.
  </Accordion>

  <Accordion title="File-backed workflows">
    Uploads go through storage first. Then the stored asset URL is passed into the downstream generation or analysis flow. This keeps your file handling consistent across all apps.
  </Accordion>
</AccordionGroup>

## Important Route Groups

<AccordionGroup>
  <Accordion title="Auth">
    **Route:** `app/api/auth/[...all]/route.ts`

    The catch-all auth handler powered by Better Auth. Handles sign-in, sign-up, sessions, and provider callbacks.
  </Accordion>

  <Accordion title="Payments">
    **Route:** `app/api/payments/[provider]/route.ts`

    The shared webhook entrypoint for supported payment providers (Polar, Stripe, LemonSqueezy). Handles purchase verification, purchase persistence, credit allocation, and plan-state updates.
  </Accordion>

  <Accordion title="Chat">
    The chat area has the deepest API surface:

    * Streaming chat
    * Conversation history
    * Document generation
    * Document upload/link/unlink/delete
    * Document vectorization
    * File upload
  </Accordion>

  <Accordion title="Generative Apps">
    Image Studio, Video Studio, Voice Studio, Vision, Audio, Marketing Plan, and Launch Simulator each have their own generation routes with their own validation and provider requirements.
  </Accordion>
</AccordionGroup>
