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

# Overview

> Architecture for the Billing Portal endpoint

## Purpose

Creates a Stripe Customer Portal session for subscription management.

## Architecture

```mermaid theme={null}
flowchart TD
    Request["POST /api/billing-portal"]
    
    subgraph auth [Authentication]
        GetOrg["Get org_id from JWT"]
    end
    
    subgraph db [Database]
        GetCustomer["Get stripe_customer_id"]
    end
    
    subgraph stripe [Stripe API]
        CreateSession["Create portal session"]
    end
    
    Request --> GetOrg
    GetOrg --> GetCustomer
    GetCustomer --> CreateSession
    CreateSession --> Response
```

## Request Body

```json theme={null}
{
  "return_url": "https://app.searchcompany.ai/settings/billing"
}
```

## Response Format

```json theme={null}
{
  "url": "https://billing.stripe.com/session/..."
}
```

## Code Location

```
src/app/apis/settings_billing/billing_portal/routes.py
```
