# Agency

## Export Agency Usage Report

> Export credit usage data for all sub-accounts as a CSV file.\
> \
> \*\*Requires Agency or Dev role.\*\* This endpoint only accepts apiKey authentication (userId is not supported).\
> \
> Returns a downloadable CSV file with columns: Sub Account ID, Sub Account Email, Sub Account Name,\
> Date, Amount, Reason, Campaign Name, Contact Name, Credit Type, Custom Keys Used, Description, AI Model.<br>

```json
{"openapi":"3.1.0","info":{"title":"DM Champ API","version":"1.0.0"},"servers":[{"url":"https://api.dmchamp.com/v1","description":"Production API Server"}],"security":[{"ApiKeyAuth":[]}],"components":{"securitySchemes":{"ApiKeyAuth":{"type":"apiKey","in":"query","name":"apiKey","description":"Your DM Champ API key. Obtain from Settings → API Keys."}},"parameters":{"ApiKeyParam":{"name":"apiKey","in":"query","description":"API key for authentication. At least one of apiKey or userId is required for protected endpoints.","required":false,"schema":{"type":"string"}}}},"paths":{"/agencies/usage/export":{"get":{"summary":"Export Agency Usage Report","description":"Export credit usage data for all sub-accounts as a CSV file.\n\n**Requires Agency or Dev role.** This endpoint only accepts apiKey authentication (userId is not supported).\n\nReturns a downloadable CSV file with columns: Sub Account ID, Sub Account Email, Sub Account Name,\nDate, Amount, Reason, Campaign Name, Contact Name, Credit Type, Custom Keys Used, Description, AI Model.\n","tags":["Agency"],"parameters":[{"$ref":"#/components/parameters/ApiKeyParam"},{"name":"from","in":"query","required":false,"schema":{"type":"string","format":"date"},"description":"Start date for the report range (YYYY-MM-DD). Defaults to 30 days ago."},{"name":"to","in":"query","required":false,"schema":{"type":"string","format":"date"},"description":"End date for the report range (YYYY-MM-DD). Defaults to today."},{"name":"subAccountId","in":"query","required":false,"schema":{"type":"string"},"description":"Filter report to a specific sub-account ID. If omitted, all sub-accounts are included."}],"responses":{"200":{"description":"CSV usage report downloaded successfully","content":{"text/csv":{"schema":{"type":"string","description":"CSV file with agency usage data. Headers: Sub Account ID, Sub Account Email,\nSub Account Name, Date, Amount, Reason, Campaign Name, Contact Name,\nCredit Type, Custom Keys Used, Description, AI Model\n"}}}},"400":{"description":"Invalid date format or date range","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean"},"error_code":{"type":"integer"},"error":{"type":"string"}}}}}},"401":{"description":"Invalid or missing API key","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean"},"error":{"type":"string"}}}}}},"403":{"description":"Authenticated user is not an Agency or Dev account","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean"},"error_code":{"type":"integer"},"error":{"type":"string"}}}}}},"500":{"description":"Internal server error","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean"},"error_code":{"type":"integer"},"error":{"type":"string"}}}}}}}}}}}
```

## Agency Public Checkout

> Creates a Stripe Checkout session for unauthenticated users (prospects) to purchase\
> credits and become sub-accounts of an agency.\
> \
> This endpoint is \*\*public\*\* — no authentication required. It is designed for shareable\
> payment links that agencies can distribute to potential sub-accounts.\
> \
> \*\*Flow\*\*:\
> 1\. Agency shares the checkout URL with query params \`agencyId\` and \`tierIndex\`\
> 2\. Endpoint validates params, fetches agency pricing config\
> 3\. Creates a Stripe Checkout session on the agency's own Stripe account (BYOK)\
> 4\. Redirects (303) to the Stripe hosted checkout page\
> 5\. Stripe collects the buyer's email and name\
> 6\. On payment success, a Firebase Auth user and Firestore doc are created automatically\
> 7\. A welcome email with a temporary password is sent to the buyer<br>

```json
{"openapi":"3.1.0","info":{"title":"DM Champ API","version":"1.0.0"},"servers":[{"url":"https://api.dmchamp.com/v1","description":"Production API Server"}],"security":[{"ApiKeyAuth":[]},{"UserIdAuth":[]}],"components":{"securitySchemes":{"ApiKeyAuth":{"type":"apiKey","in":"query","name":"apiKey","description":"Your DM Champ API key. Obtain from Settings → API Keys."},"UserIdAuth":{"type":"apiKey","in":"query","name":"userId","description":"Your DM Champ User ID. Alternative to apiKey authentication. Cannot be used for agency-only endpoints."}}},"paths":{"/checkout":{"get":{"summary":"Agency Public Checkout","description":"Creates a Stripe Checkout session for unauthenticated users (prospects) to purchase\ncredits and become sub-accounts of an agency.\n\nThis endpoint is **public** — no authentication required. It is designed for shareable\npayment links that agencies can distribute to potential sub-accounts.\n\n**Flow**:\n1. Agency shares the checkout URL with query params `agencyId` and `tierIndex`\n2. Endpoint validates params, fetches agency pricing config\n3. Creates a Stripe Checkout session on the agency's own Stripe account (BYOK)\n4. Redirects (303) to the Stripe hosted checkout page\n5. Stripe collects the buyer's email and name\n6. On payment success, a Firebase Auth user and Firestore doc are created automatically\n7. A welcome email with a temporary password is sent to the buyer\n","tags":["Agency"],"parameters":[{"name":"agencyId","in":"query","required":true,"schema":{"type":"string"},"description":"Firebase UID of the agency"},{"name":"tierIndex","in":"query","required":true,"schema":{"type":"integer","minimum":0},"description":"Zero-based index into the agency's credit pricing tiers"}],"responses":{"303":{"description":"Redirect to Stripe Checkout hosted page"},"400":{"description":"Missing or invalid parameters","content":{"text/plain":{"schema":{"type":"string"}}}},"404":{"description":"Agency not found","content":{"text/plain":{"schema":{"type":"string"}}}},"500":{"description":"Internal server error","content":{"text/plain":{"schema":{"type":"string"}}}}}}}}}
```
