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

# Issue a new credential for an agent

> POST /v1/agents/{agent_id}/credentials



## OpenAPI

````yaml /openapi/v1.json post /agents/{agentId}/credentials
openapi: 3.1.0
info:
  title: HASP AI API
  version: '2026-07-12'
  description: >-
    The HASP Public AI API is the regulated-AI substrate for healthcare and
    other

    regulated industries — identity, policy, audit, compliance, and PHI handling

    for AI inference, exposed via two surfaces:


    - **Native (`/v1/ai/*`)**: HASP-native chat with full event taxonomy, run
    lifecycle,
      and PHI metadata.
    - **Anthropic-compat (`/v1/messages`)**: Drop-in replacement for
    `@anthropic-ai/sdk` —
      change only `baseURL`. All Gateway compliance checks (BAA, credits, PHI policy) apply.

    All requests require an API key (`Authorization: Bearer
    hasp_api_live_<key>`). See

    [Authentication](https://docs.usehasp.com/ai-api/authentication) for key
    management.
servers:
  - url: https://api.usehasp.com/v1
    description: Production
security:
  - http: []
paths:
  /agents/{agentId}/credentials:
    post:
      tags:
        - Credentials
      summary: Issue a new credential for an agent
      description: POST /v1/agents/{agent_id}/credentials
      operationId: v1.agents.credentials.store
      parameters:
        - name: agentId
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  minLength: 2
                  maxLength: 255
                description:
                  type:
                    - string
                    - 'null'
                  maxLength: 500
                expires_at:
                  type: string
                  format: date-time
                revocation_policy:
                  type: string
                  enum:
                    - kill
                    - drain
                max_concurrent_invocations:
                  type:
                    - integer
                    - 'null'
                  minimum: 1
                  maximum: 1000
                app_id:
                  type:
                    - string
                    - 'null'
                project_id:
                  type:
                    - string
                    - 'null'
                granted_scopes:
                  type: array
                  items:
                    type: object
                    properties:
                      type:
                        type: string
                        enum:
                          - hasp.data.read
                          - hasp.data.write
                          - external.tool.invoke
                          - tool.destructive
                          - agent.delegate
                          - agent.compose
                          - human.escalate
                          - workflow.schedule
                          - workflow.invoke
                    required:
                      - type
                  minItems: 1
                  maxItems: 20
              required:
                - name
                - expires_at
                - revocation_policy
                - granted_scopes
      responses:
        '201':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  data:
                    type: object
                    properties:
                      credential:
                        type: array
                        items: {}
                      token:
                        type: string
                    required:
                      - credential
                      - token
                required:
                  - success
                  - data
        '401':
          description: Bearer token is missing, malformed, or revoked.
          content:
            application/json:
              schema:
                type: object
                example:
                  success: false
                  error:
                    type: authentication
                    code: INVALID_API_KEY
                    message: Bearer token is missing, malformed, or revoked.
                    param: null
                    details: null
                    retryable: false
                    request_id: 01JQREQ7XZQK5N6PZ1VVXHYB8T
                  meta:
                    request_id: 01JQREQ7XZQK5N6PZ1VVXHYB8T
        '403':
          description: ''
          content:
            application/json:
              schema:
                anyOf:
                  - type: object
                    properties:
                      success:
                        type: boolean
                      error:
                        type: object
                        properties:
                          code:
                            type: string
                          type:
                            type: string
                            const: policy_violation
                          message:
                            type: string
                          retryable:
                            type: boolean
                        required:
                          - code
                          - type
                          - message
                          - retryable
                    required:
                      - success
                      - error
                  - type: object
                    properties:
                      success:
                        type: boolean
                      error:
                        type: object
                        properties:
                          code:
                            type: string
                            const: SCOPE_EXCEEDS_DELEGATED_AUTHORITY
                          type:
                            type: string
                            const: policy_violation
                          message:
                            type: string
                            const: >-
                              None of the requested scopes are covered by this
                              credential's own granted scopes.
                          retryable:
                            type: boolean
                        required:
                          - code
                          - type
                          - message
                          - retryable
                    required:
                      - success
                      - error
                  - type: object
                    properties:
                      success:
                        type: boolean
                      error:
                        type: object
                        properties:
                          code:
                            type: string
                            const: AGENT_DELEGATION_NOT_AUTHORIZED
                          type:
                            type: string
                            const: policy_violation
                          message:
                            type: string
                            const: >-
                              This credential does not hold an agent.delegate
                              grant authorizing delegation to this agent.
                          retryable:
                            type: boolean
                        required:
                          - code
                          - type
                          - message
                          - retryable
                    required:
                      - success
                      - error
        '422':
          description: >-
            Delegation chain depth exceeds the authorizing grant's
            max_chain_depth or the target agent's policy_bounds.max_chain_depth
            ceiling (thrown by CredentialService::assertChainDepthAllowed(), not
            inline in this method).
          content:
            application/json:
              schema:
                examples:
                  - success: false
                    error:
                      code: AGENT_DELEGATION_CHAIN_DEPTH_EXCEEDED
                      type: invalid_request
                      message: Delegation chain depth 2 exceeds max_chain_depth 1.
                      retryable: false
                anyOf:
                  - type: object
                    properties:
                      success:
                        type: boolean
                      error:
                        type: object
                        properties:
                          code:
                            type: string
                          type:
                            type: string
                            const: unprocessable
                          message:
                            type: string
                          field:
                            type: string
                          errors:
                            type: string
                          retryable:
                            type: boolean
                        required:
                          - code
                          - type
                          - message
                          - field
                          - errors
                          - retryable
                    required:
                      - success
                      - error
                  - type: object
                    properties:
                      success:
                        type: boolean
                      error:
                        type: object
                        properties:
                          code:
                            type: string
                            const: DELEGATING_USER_REQUIRED
                          type:
                            type: string
                            const: unprocessable
                          message:
                            type: string
                            const: >-
                              Credentials must be issued on behalf of a specific
                              user. Use a personal API key.
                          retryable:
                            type: boolean
                        required:
                          - code
                          - type
                          - message
                          - retryable
                    required:
                      - success
                      - error
                  - type: object
                    properties:
                      success:
                        type: boolean
                      error:
                        type: object
                        properties:
                          code:
                            type: string
                            const: INVALID_SCOPE_TYPE
                          type:
                            type: string
                            const: unprocessable
                          message:
                            type: string
                          field:
                            type: string
                          retryable:
                            type: boolean
                        required:
                          - code
                          - type
                          - message
                          - field
                          - retryable
                    required:
                      - success
                      - error
                  - type: object
                    properties:
                      success:
                        type: boolean
                      error:
                        type: object
                        properties:
                          code:
                            type: string
                            const: TOOL_ID_REQUIRED
                          type:
                            type: string
                            const: unprocessable
                          message:
                            type: string
                            const: >-
                              Scope type [external.tool.invoke] requires a
                              tool_id.
                          field:
                            type: string
                          retryable:
                            type: boolean
                        required:
                          - code
                          - type
                          - message
                          - field
                          - retryable
                    required:
                      - success
                      - error
                  - type: object
                    properties:
                      success:
                        type: boolean
                      error:
                        type: object
                        properties:
                          code:
                            type: string
                            const: AGENT_ARCHIVED
                          type:
                            type: string
                            const: unprocessable
                          message:
                            type: string
                            const: Cannot issue credentials for an archived agent.
                          retryable:
                            type: boolean
                        required:
                          - code
                          - type
                          - message
                          - retryable
                    required:
                      - success
                      - error
components:
  securitySchemes:
    http:
      type: http
      scheme: bearer

````