Sample - OpenAI API
POST/organization/projects/{project_id}/service_accounts/{service_account_id}/api_keys

Create an API key for a service account

Creates an API key for a service account in a project. Use project_id and service_account_id to identify the target service account, and optionally provide a name, scopes, or an expiration period for the key.

  • RetriesRetries up to 2×, 500ms backoff, 30s timeout.

2 parameters · 3 body fields
project_idstringrequired
The string identifier of the project containing the service account.
service_account_idstringrequired
The string identifier of the service account for which to create the API key.

Optional service account API key creation payload. All fields are optional.

namestringoptional
API key name.
scopesarray<string>optional
API key scopes.
expires_in_secondsintegeroptional
The number of seconds until the API key expires. Must be between 1 and 31536000, or null for no expiration.

1 status code
200Returns the created service account API key, including its unredacted `value`, name, creation timestamp, optional expiration timestamp, and identifier.
objectstringrequired
The object type, which is always `organization.project.service_account.api_key`
Allowed:organization.project.service_account.api_keyDefault:organization.project.service_account.api_key
valuestringrequired
The unredacted API key value.
namestringrequired
The name of the API key.
created_atintegerrequired
The Unix timestamp (in seconds) when the API key was created.
expires_atintegeroptional
The Unix timestamp (in seconds) when the API key expires, or null if it does not expire.
idstringrequired
The identifier of the API key.

Error handling

project_id and service_account_id must identify the target project and service account, and both values must be strings. If provided, expires_in_seconds must be between 1 and 31536000 seconds or explicitly null.