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

# Create an Organization API Key

Requires an active organization — without one, the org lookup this performs fails and the request returns `404` rather than proceeding. The secret is generated here, hashed with Argon2id, and stored in the `pats` table (org-scoped by row-level security). Creates the paired Logto personal access token first, then the local `pats` row; if the local insert fails, the Logto token is deleted to avoid leaving an orphaned credential.

### Auth

Requires `pats:create` and an active organization, since the key is created under the token's organization. Every default role carries `pats:create`: the key is minted under the caller's own Logto user and, at exchange, carries only that user's scopes, so it can't grant more access than the caller already has.

### Response

`200 OK` — same shape as one element of the [List Organization API Keys](/api-reference/pats/list-org-keys) response, except:

| Field     | Type     | Description                                                                                                   |
| --------- | -------- | ------------------------------------------------------------------------------------------------------------- |
| `pat_key` | `string` | The full secret, `ak_<key_id>.<secret>` — shown **exactly once**. Store it now; it cannot be retrieved again. |

### Errors

| Status          | Cause                                                                                                                                                                                |
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `404 Not Found` | The token's organization claim doesn't resolve to a known AnyCRM organization (`Organization not found for logto_org_id=...`) — typically means no active organization was selected. |


## OpenAPI

````yaml POST /organization-pats
openapi: 3.1.0
info:
  title: anycrm-api
  version: 0.0.1
servers: []
security: []
tags:
  - name: Customer Intelligence
    description: >-
      Company research and ICP-fit scoring — create a research run, track its
      progress, and read back scored companies as leads.
  - name: Outreach
    description: >-
      The cold-email management console — domains, mailboxes, and campaigns — as
      a thin control plane over the SalesForge stack.
  - name: AnyCard
    description: >-
      Authenticated CRUD for AnyCard, the org's digital business-card /
      lead-capture product.
  - name: AnyCard Events
    description: >-
      Event-attribution analytics for AnyCard — which captured leads converted,
      broken down by source, owner, and deal.
  - name: AnyCard Share Links
    description: >-
      Unauthenticated endpoints reached by anyone who scans a QR code or opens a
      shared AnyCard link.
  - name: AI
    description: >-
      A streaming (SSE) AI chat endpoint with account-commit actions it can take
      on the caller's behalf.
  - name: Analytics Assistant
    description: >-
      The natural-language analytics assistant — a guarded text-to-SQL loop
      (SSE) that answers ad-hoc questions over the org's CRM data as a
      least-privilege, read-only database role.
  - name: Account Readiness
    description: >-
      Account Readiness Profiles — AI-scored signals on whether an account is
      ready for outreach or expansion, computed via a Temporal workflow.
  - name: Integrations
    description: >-
      Pipedream Connect — issuing connect tokens and managing the org's
      connected third-party accounts.
  - name: Feedback
    description: >-
      User-submitted platform feedback (bug reports, feature requests) — global,
      not scoped to one organization.
  - name: Public Media
    description: >-
      Unauthenticated image reads for publicly-embeddable assets (card photos,
      inline email images) — allowlisted by key shape; everything else in the
      storage bucket stays private.
  - name: Service Health
    description: Service liveness.
paths:
  /organization-pats:
    post:
      tags:
        - PATs
      summary: Create Pat
      operationId: create_pat_organization_pats_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PatCreateRequest'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PatResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - HTTPBearer: []
components:
  schemas:
    PatCreateRequest:
      properties:
        name:
          type: string
          title: Name
          description: Label for the org API key, shown in Settings → Tokens.
        expires_at:
          anyOf:
            - type: integer
            - type: 'null'
          title: Expires At
          description: >-
            Optional expiry as epoch milliseconds (not seconds — a value below
            10^12 is rejected). Omit for a key that never expires.
      type: object
      required:
        - name
      title: PatCreateRequest
    PatResponse:
      properties:
        id:
          type: string
          title: Id
        name:
          type: string
          title: Name
        pat_key:
          anyOf:
            - type: string
            - type: 'null'
          title: Pat Key
        expires_at:
          anyOf:
            - type: string
            - type: 'null'
          title: Expires At
        created_at:
          anyOf:
            - type: string
            - type: 'null'
          title: Created At
        key_id:
          type: string
          title: Key Id
        owner_user_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Owner User Id
        owner_name:
          anyOf:
            - type: string
            - type: 'null'
          title: Owner Name
      type: object
      required:
        - id
        - name
        - key_id
      title: PatResponse
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer

````