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

# Create a credential

> Creates a credential under the given package with a `credentialName` and at least one field. Each field has a `fieldType` (email, username, password, api_token, phone_number, two_factor_secret, or backup_codes) and a value.



## OpenAPI

````yaml /api-reference/credentials-ref/credential-packages.yaml post /credentials/packages/{packageName}
openapi: 3.1.0
info:
  title: Credential Packages
  version: v1
servers:
  - description: Droidrun Cloud API
    url: https://api.mobilerun.ai/v1
security:
  - bearerAuth: []
paths:
  /credentials/packages/{packageName}:
    post:
      tags:
        - Credential Packages
      summary: Create a credential
      description: >-
        Creates a credential under the given package with a `credentialName` and
        at least one field. Each field has a `fieldType` (email, username,
        password, api_token, phone_number, two_factor_secret, or backup_codes)
        and a value.
      operationId: createCredentialWithFields
      parameters:
        - in: path
          name: packageName
          required: true
          schema:
            maxLength: 200
            minLength: 1
            type: string
      requestBody:
        content:
          application/json:
            schema:
              properties:
                credentialName:
                  maxLength: 50
                  minLength: 3
                  pattern: ^[a-z0-9_-]+$
                  type: string
                fields:
                  items:
                    properties:
                      fieldType:
                        enum:
                          - email
                          - username
                          - password
                          - api_token
                          - phone_number
                          - two_factor_secret
                          - backup_codes
                        type: string
                      value:
                        minLength: 1
                        type: string
                    required:
                      - fieldType
                      - value
                    type: object
                  minItems: 1
                  type: array
              required:
                - credentialName
                - fields
              type: object
      responses:
        '200':
          content:
            application/json:
              schema:
                properties:
                  data:
                    $ref: '#/components/schemas/Credential'
                  message:
                    type: string
                  success:
                    enum:
                      - true
                    type: boolean
                required:
                  - success
                  - message
                  - data
                type: object
          description: Credential created
        '400':
          content:
            application/json:
              schema:
                anyOf:
                  - $ref: '#/components/schemas/CredentialErrorResponse'
                  - $ref: '#/components/schemas/ApiErrorEnvelope'
          description: >-
            Bad Request — invalid_request, package_exists, create_failed,
            update_failed, protocol_change_not_allowed (legacy body + additive
            code/message), or a generic request validation failure
        '401':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorEnvelope'
          description: Unauthorized
        '409':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CredentialErrorResponse'
          description: Conflict (legacy body + additive code/message)
        '429':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CredentialErrorResponse'
          description: Credential source rate limited
        '500':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InternalServerError'
          description: Internal Server Error
      x-codeSamples:
        - lang: JavaScript
          source: >-
            import Mobilerun from '@mobilerun/sdk';


            const client = new Mobilerun({
              apiKey: process.env['MOBILERUN_CLOUD_API_KEY'], // This is the default and can be omitted
            });


            const credential = await
            client.credentials.packages.credentials.create('x', {
              credentialName: '26f1kl_-n-71',
              fields: [{ fieldType: 'email', value: 'x' }],
            });


            console.log(credential.data);
        - lang: Python
          source: |-
            import os
            from mobilerun_sdk import Mobilerun

            client = Mobilerun(
                api_key=os.environ.get("MOBILERUN_CLOUD_API_KEY"),  # This is the default and can be omitted
            )
            credential = client.credentials.packages.credentials.create(
                package_name="x",
                credential_name="26f1kl_-n-71",
                fields=[{
                    "field_type": "email",
                    "value": "x",
                }],
            )
            print(credential.data)
components:
  schemas:
    Credential:
      properties:
        createdBy:
          type:
            - string
            - 'null'
        credentialName:
          type: string
        fields:
          items:
            properties:
              fieldType:
                enum:
                  - email
                  - username
                  - password
                  - api_token
                  - phone_number
                  - two_factor_secret
                  - backup_codes
                type: string
              value:
                minLength: 1
                type: string
            required:
              - fieldType
              - value
            type: object
          type: array
        link:
          properties:
            fieldMap:
              items:
                properties:
                  fieldId:
                    minLength: 1
                    type: string
                  fieldType:
                    enum:
                      - email
                      - username
                      - password
                      - api_token
                      - phone_number
                      - two_factor_secret
                      - backup_codes
                    type: string
                required:
                  - fieldType
                  - fieldId
                type: object
              minItems: 1
              type: array
            itemId:
              minLength: 1
              type: string
            itemTitle:
              type: string
            provider:
              enum:
                - onepassword
              type: string
            vaultId:
              minLength: 1
              type: string
            vaultName:
              type: string
          required:
            - provider
            - vaultId
            - vaultName
            - itemId
            - itemTitle
            - fieldMap
          type: object
        ownerId:
          type: string
        packageName:
          type: string
        secretPath:
          type: string
        source:
          enum:
            - mobilerun
            - onepassword
          type: string
        userId:
          deprecated: true
          description: >-
            Deprecated: use createdBy (same value — the creating actor). Null
            for credentials created before rollout.
          type:
            - string
            - 'null'
      required:
        - ownerId
        - createdBy
        - userId
        - packageName
        - secretPath
        - credentialName
        - fields
      type: object
    CredentialErrorResponse:
      properties:
        code:
          $ref: '#/components/schemas/CredentialErrorCode'
        message:
          type: string
      required:
        - code
        - message
      type: object
    ApiErrorEnvelope:
      properties:
        code:
          type: string
        details: {}
        message:
          type: string
        retryAfterSeconds:
          type: number
        traceId:
          type: string
      required:
        - code
        - message
      type: object
    InternalServerError:
      properties:
        code:
          type: string
        message:
          type: string
        traceId:
          type: string
      required:
        - code
        - message
      type: object
    CredentialErrorCode:
      enum:
        - credential_read_only
        - credential_source_unavailable
        - credential_source_rate_limited
        - onepassword_not_connected
        - onepassword_token_invalid
        - onepassword_no_vaults
        - onepassword_reference_invalid
        - invalid_request
        - package_exists
        - credential_not_found
        - proxy_not_found
        - create_failed
        - update_failed
        - protocol_change_not_allowed
      type: string
  securitySchemes:
    bearerAuth:
      bearerFormat: Opaque
      description: Bearer token via Authorization header
      scheme: bearer
      type: http

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.