Create Credential

Updated at:

Creates a Credential in a specified Vault. The auth field currently supports only the environment_variable type. Sensitive values are write-only and never returned in responses.

Prerequisites

Endpoint and authentication configured. For details, see Overview and authentication.

Endpoint

POST/vaults/{vault_id}/credentials

Path parameters

vault_idstringRequired

Vault ID, format vlt_xxx

Request body

authobjectRequired

Authentication information, always of the environment_variable type.

display_namestringOptional

Human-readable name of the Credential, max 255 characters

metadataobjectOptional

Custom key-value pairs for business metadata

auth type

The auth field currently supports only the environment_variable type, which injects as an environment variable into sessions.

typestringRequired

Always environment_variable

secret_namestringRequired

Environment variable name. Must match ^[a-zA-Z][a-zA-Z0-9_]*$: start with a letter; only letters, digits, and underscores. Immutable after creation

secret_valuestringRequired

Environment variable value; write-only, never returned in responses

networkingobjectRequired

Network policy that restricts real-key substitution to requests sent to the specified hosts

networking.allowed_hostsarrayRequired

List of hosts allowed for real-key substitution. Supports *.example.com wildcard subdomains, up to 10 entries. Set * to apply to all hosts

injection_locationobjectRequired

Injection location that marks where the secret is written into the request. The location is the request header; placeholders in the request body and query parameters are not replaced

injection_location.headerbooleanOptional

Whether to enable request-header replacement. Set to true

NoteWithin one vault, secret_name values must be unique. Creating a duplicate returns 409 CREDENTIAL_SECRET_NAME_DUPLICATE ("A credential with the same secret name already exists in this vault").

Request example

curl -X POST "$AGENTSTUDIO_URL/vaults/vlt_xxx/credentials" \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "display_name": "Third-party API key",
    "auth": {
      "type": "environment_variable",
      "secret_name": "API_KEY",
      "secret_value": "sk-xxxx",
      "networking": {
        "allowed_hosts": [
          "api.example.com",
          "*.example.com"
        ]
      },
      "injection_location": {
        "header": true
      }
    }
  }'

Response fields

idstring

Credential ID, format cred_xxx

typestring

Always credential

vault_idstring

Vault ID that the Credential belongs to

display_namestring

Human-readable name of the Credential

authobject

Authentication information with sensitive values masked (e.g. secret_value is not returned)

auth.typestring

Auth type; currently only environment_variable

auth.secret_namestring

Environment variable name

auth.networkingobject

Network policy

auth.networking.allowed_hostsarray

List of hosts allowed for real-key substitution

auth.injection_locationobject

Injection location. The location is the request header; placeholders in the request body and query parameters are not replaced

auth.injection_location.headerboolean

Whether to enable request-header replacement

metadataobject

Custom key-value pairs

archived_atstring | null

Archive timestamp; null if not archived

created_atstring

Creation time, ISO 8601

updated_atstring

Last update time, ISO 8601

request_idstring

Unique request identifier

Response example

{
  "id": "cred_xxx",
  "type": "credential",
  "vault_id": "vlt_xxx",
  "display_name": "Third-party API key",
  "auth": {
    "type": "environment_variable",
    "secret_name": "API_KEY",
    "networking": {
      "allowed_hosts": [
        "api.example.com",
        "*.example.com"
      ]
    },
    "injection_location": {
      "header": true
    }
  },
  "metadata": {},
  "archived_at": null,
  "created_at": "2026-07-10T08:00:00Z",
  "updated_at": "2026-07-10T08:00:00Z",
  "request_id": "req_xxx"
}

Error codes

HTTP statusError codeDescription
400InvalidParameterRequired parameter missing or invalid.
401InvalidApiKeyInvalid API key provided.
409CREDENTIAL_SECRET_NAME_DUPLICATEsecret_name already exists in the vault.