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

# Create a trading account with broker credential

> Creates a trading account and stores its broker credential as an encrypted WorkOS Vault object. Only organization admins can create credentials. Paper credentials are allowed for admins; live credentials additionally require the Trading Live entitlement. The organization's billing tier caps the number of broker connections; the request is rejected once that limit is reached. The response returns the created trading-account id and broker-credential id.



## OpenAPI

````yaml /api-reference/credentials.openapi.json post /v1/trading-accounts
openapi: 3.1.0
info:
  title: credentials
  description: ''
  license:
    name: ''
  version: 0.1.0
servers:
  - url: https://api.anthid.com
    description: Production
security: []
tags:
  - name: Credentials
    description: Trading-account metadata and lifecycle operations
  - name: Credentials
    description: >-
      Broker credential creation, metadata, secret access, and lifecycle
      operations
paths:
  /v1/trading-accounts:
    post:
      tags:
        - Credentials
      summary: Create a trading account with broker credential
      description: >-
        Creates a trading account and stores its broker credential as an
        encrypted WorkOS Vault object. Only organization admins can create
        credentials. Paper credentials are allowed for admins; live credentials
        additionally require the Trading Live entitlement. The organization's
        billing tier caps the number of broker connections; the request is
        rejected once that limit is reached. The response returns the created
        trading-account id and broker-credential id.
      operationId: createTradingAccount
      requestBody:
        description: >-
          Broker-specific credential payload. Lightspeed and Alpaca credentials
          are currently supported.
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/BrokerCredentialVariant'
            example:
              Lightspeed:
                account_id: LS-123456
                api_key: lightspeed-api-key
                environment: paper
        required: true
      responses:
        '201':
          description: Credential created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateCredentialResponse'
              example:
                broker_credential_id: 550e8400-e29b-41d4-a716-446655440111
                trading_account_id: 550e8400-e29b-41d4-a716-446655440000
        '400':
          description: >-
            Credential payload is invalid, broker type is unsupported,
            organization entitlements could not be resolved, or the
            organization's broker-connection limit for its billing tier has been
            reached
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Missing or invalid bearer token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: >-
            Caller is not an organization admin or lacks the required
            live-trading entitlement
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: Credential already exists for this broker account
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          description: Caller exceeded the request rate limit
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Unexpected server error while creating the credential
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      security:
        - bearerAuth: []
components:
  schemas:
    BrokerCredentialVariant:
      oneOf:
        - type: object
          required:
            - Lightspeed
          properties:
            Lightspeed:
              $ref: '#/components/schemas/LightspeedCredential'
        - type: object
          required:
            - Alpaca
          properties:
            Alpaca:
              $ref: '#/components/schemas/AlpacaCredential'
        - type: string
          enum:
            - Unspecified
    CreateCredentialResponse:
      type: object
      required:
        - trading_account_id
        - broker_credential_id
      properties:
        broker_credential_id:
          type: string
          format: uuid
        trading_account_id:
          type: string
          format: uuid
    Error:
      oneOf:
        - type: object
          required:
            - EncryptionError
          properties:
            EncryptionError:
              type: string
        - type: object
          required:
            - WorkOsError
          properties:
            WorkOsError:
              type: string
        - type: object
          required:
            - KvError
          properties:
            KvError:
              type: string
        - type: object
          required:
            - StreamError
          properties:
            StreamError:
              type: string
        - type: object
          required:
            - InternalError
          properties:
            InternalError:
              type: string
        - type: object
          required:
            - ThirdPartyError
          properties:
            ThirdPartyError:
              type: string
        - type: object
          required:
            - ParseError
          properties:
            ParseError:
              type: string
        - type: object
          required:
            - NotFound
          properties:
            NotFound:
              type: string
        - type: object
          required:
            - AlreadyExists
          properties:
            AlreadyExists:
              type: string
        - type: object
          required:
            - BadRequest
          properties:
            BadRequest:
              type: string
        - type: object
          required:
            - Forbidden
          properties:
            Forbidden:
              type: string
        - type: object
          required:
            - Unauthorized
          properties:
            Unauthorized:
              type: string
        - type: object
          required:
            - Database
          properties:
            Database:
              type: string
        - type: object
          required:
            - TooManyRequests
          properties:
            TooManyRequests:
              type: string
        - type: object
          required:
            - BrokerError
          properties:
            BrokerError:
              type: string
        - type: object
          required:
            - AuthError
          properties:
            AuthError:
              type: string
        - type: object
          required:
            - InvalidInput
          properties:
            InvalidInput:
              type: string
        - type: object
          required:
            - ConnectionLimitExceeded
          properties:
            ConnectionLimitExceeded:
              type: string
    LightspeedCredential:
      type: object
      required:
        - account_id
        - environment
        - api_key
      properties:
        account_id:
          type: string
        api_key:
          type: string
        environment:
          $ref: '#/components/schemas/BrokerEnvironment'
    AlpacaCredential:
      type: object
      required:
        - environment
        - api_key_id
        - api_key_secret
      properties:
        api_key_id:
          type: string
        api_key_secret:
          type: string
        environment:
          $ref: '#/components/schemas/BrokerEnvironment'
    BrokerEnvironment:
      type: string
      enum:
        - paper
        - live
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

````