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

# Create a credential

> Create a new integration credential. The auth method is inferred from the `auth_data` payload (`api_key`, `token`/`bearer_token`, or `access_token` + `oauth_config`) or set explicitly via `auth_type` (`modulex_key`, `custom`). Requires the organization admin or owner role.



## OpenAPI

````yaml /api-reference/openapi.json post /credentials
openapi: 3.0.3
info:
  title: ModuleX API
  version: 0.1.2
  description: >-
    ModuleX REST API. Authenticate with a user API key (`Authorization: Bearer
    mx_live_*`, or the `X-API-KEY` header) and supply the organization context
    header `X-Organization-ID` on org-scoped endpoints. Routers carry NO `/v1`
    version segment. Billing-gated surfaces (workflow run, managed knowledge
    search) reject before any write with a flat `DenialEnvelope` (402/403/429).
servers:
  - url: https://api.modulex.dev
    description: Production
security:
  - bearerAuth: []
    orgHeader: []
tags:
  - name: Workflows
    description: Create, read, update and delete workflow definitions.
  - name: Runs
    description: Execute workflows. Subject to the billing admission gate.
  - name: Schedules
    description: Recurring (cron / interval) workflow executions.
  - name: Knowledge
    description: Knowledge bases and semantic search.
  - name: Credentials
    description: Integration credentials (API key, bearer, OAuth2, ModuleX-managed).
  - name: Integrations
    description: Catalog of available tools, LLM providers and knowledge providers.
  - name: Organizations
    description: Organization management.
  - name: API keys
    description: User-owned API keys for programmatic access.
paths:
  /credentials:
    post:
      tags:
        - Credentials
      summary: Create a credential
      description: >-
        Create a new integration credential. The auth method is inferred from
        the `auth_data` payload (`api_key`, `token`/`bearer_token`, or
        `access_token` + `oauth_config`) or set explicitly via `auth_type`
        (`modulex_key`, `custom`). Requires the organization admin or owner
        role.
      operationId: createCredential
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CredentialCreate'
      responses:
        '201':
          description: The created credential.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Credential'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '422':
          $ref: '#/components/responses/ValidationError'
components:
  schemas:
    CredentialCreate:
      type: object
      required:
        - integration_name
      description: >-
        Auth method is inferred from `auth_data` keys or set explicitly via
        `auth_type`.
      properties:
        integration_name:
          type: string
          description: Integration this credential is for (e.g. openai, slack).
        display_name:
          type: string
          nullable: true
        auth_type:
          type: string
          nullable: true
          description: Explicit auth type for the modulex_key / custom paths.
          enum:
            - modulex_key
            - custom
        auth_data:
          type: object
          description: >-
            Secret material. Inferred type: `api_key` → API key;
            `token`/`bearer_token` → bearer; `access_token` (with
            `oauth_config`) → OAuth2.
          additionalProperties: true
        oauth_config:
          type: object
          additionalProperties: true
          description: OAuth2 client config (required for OAuth2 credentials).
        metadata:
          type: object
          additionalProperties: true
        make_default:
          type: boolean
          default: false
        expires_at:
          type: string
          format: date-time
          nullable: true
    Credential:
      type: object
      description: An integration credential (no sensitive data).
      properties:
        credential_id:
          type: string
          format: uuid
        integration_name:
          type: string
        integration_type:
          type: string
          nullable: true
        display_name:
          type: string
        auth_type:
          type: string
        is_default:
          type: boolean
        created_at:
          type: string
          format: date-time
          nullable: true
        updated_at:
          type: string
          format: date-time
          nullable: true
        last_used_at:
          type: string
          format: date-time
          nullable: true
        expires_at:
          type: string
          format: date-time
          nullable: true
        credentials_metadata:
          type: object
          nullable: true
          additionalProperties: true
    Error:
      type: object
      description: Standard FastAPI error response.
      properties:
        detail:
          description: >-
            Human-readable error message, or a structured object (some endpoints
            return `{message, code, ...}`).
          oneOf:
            - type: string
            - type: object
              additionalProperties: true
    HTTPValidationError:
      type: object
      properties:
        detail:
          type: array
          items:
            $ref: '#/components/schemas/ValidationErrorItem'
    ValidationErrorItem:
      type: object
      required:
        - loc
        - msg
        - type
      properties:
        loc:
          type: array
          items:
            oneOf:
              - type: string
              - type: integer
        msg:
          type: string
        type:
          type: string
  responses:
    BadRequest:
      description: The request was malformed or failed a business rule.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Unauthorized:
      description: >-
        Authentication required or invalid. Provide `Authorization: Bearer
        <key>` or `X-API-KEY`.
      headers:
        WWW-Authenticate:
          schema:
            type: string
          description: Bearer
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Forbidden:
      description: The caller lacks the required role or access to the resource.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    ValidationError:
      description: Request validation failed (FastAPI 422).
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/HTTPValidationError'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        User API key: `Authorization: Bearer mx_live_*`. The `X-API-KEY:
        mx_live_*` header is also accepted.
    orgHeader:
      type: apiKey
      in: header
      name: X-Organization-ID
      description: Required organization context for org-scoped endpoints.

````