The Credentials API allows you to create, retrieve, update, list, and delete server-managed credentials (such as API keys, OAuth2 tokens, HTTP Bearer tokens, and environment variables) to authenticate tool calls and MCP servers.
[View as markdown](https://ai.google.dev/static/api/credentials.md.txt) [View the OpenAPI Spec](https://ai.google.dev/static/api/interactions.openapi.json)

> [!NOTE]
> This API is in Beta. Endpoints are under `/v1beta/`.

## CreateCredential

post https://generativelanguage.googleapis.com/v1beta/credentials Creates a credential.
- [Request body](https://ai.google.dev/api/credentials#CreateCredential.request_body)
- [Response](https://ai.google.dev/api/credentials#CreateCredential.response)

### Request body

The request body structure depends on the interaction mode you choose:
EnvironmentVariableConfig Configuration for environment variable credentials.
id string (required) No description provided.
injection_location InjectionLocation or array (InjectionLocation) (required) Required. Locations where the environment variable can be injected in
outgoing HTTP requests. Must contain at least one location.
Accepts either a single location (e.g. "header") or an array of locations.
<br />

#### Possible values

- `header`

  Injected into HTTP request headers.
- `query`

  Injected into HTTP URL query parameters.
- `body`

  Injected into HTTP request body.
trusted_domains array (string) (optional) Optional. List of domains allowed to receive this environment variable
value in HTTP requests.
type object (required) No description provided.
value string (required) Required. Input only. Secret value of the environment variable. Write-only; never
returned in responses.
HttpBearerConfig Configuration for HTTP Bearer token credentials.
header_name string (optional) Optional. Header name to inject the token into. Defaults to
'Authorization'.
id string (required) No description provided.
prefix string (optional) Optional. Prefix to prepend to the token. Defaults to 'Bearer'. Set to ''
for no prefix.
token string (required) Required. Input only. The static bearer token. Write-only; never returned in responses.
type object (required) No description provided.
OAuth2Config Configuration for OAuth2 credentials with automatic token refresh.
client_id string (required) Required. OAuth2 client ID.
client_secret string (required) Required. Input only. OAuth2 client secret. Write-only; never returned in responses.
id string (required) No description provided.
refresh_token string (required) Required. Input only. OAuth2 refresh token. Write-only; never returned in responses.
scopes array (string) (optional) Optional. List of OAuth2 scopes.
token_url string (required) Required. OAuth2 token endpoint URL for refreshing access tokens.
type object (required) No description provided.

### Response

If successful, the response body contains data with the following structure:
create_time string (optional) Output only. The timestamp when the credential was created.
id string (optional) Required. Output only. Identifier. Unique identifier for the credential.
status enum (string) (optional) Output only. Current status of the credential.

Possible
values:

- `active`

  The credential is active and valid for use.
- `revoked`

  The credential has been revoked and is no longer valid.
type enum (string) (optional) Required. Output only. The type of credential.

Possible
values:

- `bearer_token`

  Static token injected as header. No refresh logic.
- `oauth2`

  Auto-refresh expired access tokens using stored refresh token.
- `environment_variable`

  Environment variable injected into sandbox container.
update_time string (optional) Output only. The timestamp when the credential was last updated.

### Example

<iframe src="https:///frame/api/credentials_9c0191dce34fd82373eb67e74b160862657771f7fc52e3438cd0c6e35b41569f.frame" class="framebox inherit-locale " allow="clipboard-write https://" allowfullscreen is-upgraded></iframe>

#### Example Response

```json
{
  "create_time": "string",
  "id": "string",
  "status": "active",
  "type": "bearer_token",
  "update_time": "string"
}
```

## ListCredentials

get https://generativelanguage.googleapis.com/v1beta/credentials Lists credentials for a project.
- [Path / Query parameters](https://ai.google.dev/api/credentials#ListCredentials.PATH_PARAMETERS)
- [Response](https://ai.google.dev/api/credentials#ListCredentials.response)

### Path / Query Parameters

page_size integer (optional) Optional. Maximum number of credentials to return.
If unspecified, defaults to 50. Maximum is 1000.
page_token string (optional) Optional. Pagination token.

### Response

If successful, the response body contains data with the following structure:
credentials array ([Credential](https://ai.google.dev/api/credentials#Resource:Credential)) (optional) No description provided.
next_page_token string (optional) No description provided.

### Example

<iframe src="https:///frame/api/credentials_397eddd880195907205fe0bc2d8f7053b0a1faef4c5ea9dba5bb36b96e318fa2.frame" class="framebox inherit-locale " allow="clipboard-write https://" allowfullscreen is-upgraded></iframe>

#### Example Response

```json
{
  "credentials": [
    {
      "create_time": "string",
      "id": "string",
      "status": "active",
      "type": "bearer_token",
      "update_time": "string"
    }
  ],
  "next_page_token": "string"
}
```

## GetCredential

get https://generativelanguage.googleapis.com/v1beta/credentials/{id} Gets metadata of a single credential (no secret fields).
- [Response](https://ai.google.dev/api/credentials#GetCredential.response)

### Response

If successful, the response body contains data with the following structure:
create_time string (optional) Output only. The timestamp when the credential was created.
id string (optional) Required. Output only. Identifier. Unique identifier for the credential.
status enum (string) (optional) Output only. Current status of the credential.

Possible
values:

- `active`

  The credential is active and valid for use.
- `revoked`

  The credential has been revoked and is no longer valid.
type enum (string) (optional) Required. Output only. The type of credential.

Possible
values:

- `bearer_token`

  Static token injected as header. No refresh logic.
- `oauth2`

  Auto-refresh expired access tokens using stored refresh token.
- `environment_variable`

  Environment variable injected into sandbox container.
update_time string (optional) Output only. The timestamp when the credential was last updated.

### Example

<iframe src="https:///frame/api/credentials_68289b7a4e9edb43f38c988f0d14dac4c1e392d605f94124c3945c533be39873.frame" class="framebox inherit-locale " allow="clipboard-write https://" allowfullscreen is-upgraded></iframe>

#### Example Response

```json
{
  "create_time": "string",
  "id": "string",
  "status": "active",
  "type": "bearer_token",
  "update_time": "string"
}
```

## UpdateCredential

patch https://generativelanguage.googleapis.com/v1beta/credentials/{id} Updates a credential.
- [Path / Query parameters](https://ai.google.dev/api/credentials#UpdateCredential.PATH_PARAMETERS)
- [Request body](https://ai.google.dev/api/credentials#UpdateCredential.request_body)
- [Response](https://ai.google.dev/api/credentials#UpdateCredential.response)

### Path / Query Parameters

update_mask string (optional) Optional. The list of fields to update.

### Request body

The request body structure depends on the interaction mode you choose:
EnvironmentVariableUpdateConfig Configuration for updating environment variable credentials.
injection_location InjectionLocation or array (InjectionLocation) (optional) Optional. Locations where the environment variable can be injected in
outgoing HTTP requests.
Accepts either a single location (e.g. "header") or an array of locations.
<br />

#### Possible values

- `header`

  Injected into HTTP request headers.
- `query`

  Injected into HTTP URL query parameters.
- `body`

  Injected into HTTP request body.
trusted_domains array (string) (optional) Optional. List of domains allowed to receive this environment variable
value in HTTP requests.
type object (required) No description provided.
value string (optional) Optional. Input only. Secret value of the environment variable. Write-only; never
returned in responses.
HttpBearerUpdateConfig Configuration for updating HTTP Bearer token credentials.
header_name string (optional) Optional. Header name to inject the token into. Defaults to
'Authorization'.
prefix string (optional) Optional. Prefix to prepend to the token. Defaults to 'Bearer'. Set to ''
for no prefix.
token string (optional) Optional. Input only. The static bearer token. Write-only; never returned in responses.
type object (required) No description provided.
OAuth2UpdateConfig Configuration for updating OAuth2 credentials.
client_id string (optional) Optional. OAuth2 client ID.
client_secret string (optional) Optional. Input only. OAuth2 client secret. Write-only; never returned in responses.
refresh_token string (optional) Optional. Input only. OAuth2 refresh token. Write-only; never returned in responses.
scopes array (string) (optional) Optional. List of OAuth2 scopes.
token_url string (optional) Optional. OAuth2 token endpoint URL for refreshing access tokens.
type object (required) No description provided.

### Response

If successful, the response body contains data with the following structure:
create_time string (optional) Output only. The timestamp when the credential was created.
id string (optional) Required. Output only. Identifier. Unique identifier for the credential.
status enum (string) (optional) Output only. Current status of the credential.

Possible
values:

- `active`

  The credential is active and valid for use.
- `revoked`

  The credential has been revoked and is no longer valid.
type enum (string) (optional) Required. Output only. The type of credential.

Possible
values:

- `bearer_token`

  Static token injected as header. No refresh logic.
- `oauth2`

  Auto-refresh expired access tokens using stored refresh token.
- `environment_variable`

  Environment variable injected into sandbox container.
update_time string (optional) Output only. The timestamp when the credential was last updated.

### Example

<iframe src="https:///frame/api/credentials_9225e685246402d49f07791cf2b2a85c1863d4b1e57cdb27b2286763ca103f1d.frame" class="framebox inherit-locale " allow="clipboard-write https://" allowfullscreen is-upgraded></iframe>

#### Example Response

```json
{
  "create_time": "string",
  "id": "string",
  "status": "active",
  "type": "bearer_token",
  "update_time": "string"
}
```

## DeleteCredential

delete https://generativelanguage.googleapis.com/v1beta/credentials/{id} Deletes a credential. Fails if referenced by active triggers.
- [Response](https://ai.google.dev/api/credentials#DeleteCredential.response)

### Response

If successful, the response is empty.

### Example

<iframe src="https:///frame/api/credentials_ca08059f78fb88242949d4ed2a0e93a49c1a6372eb958db3d77a2dbe86fc3c8c.frame" class="framebox inherit-locale " allow="clipboard-write https://" allowfullscreen is-upgraded></iframe>

## Resources

### Credential

Server-managed credential resource stored in Secret Manager.

#### Fields

create_time string (optional) Output only. The timestamp when the credential was created.
id string (optional) Required. Output only. Identifier. Unique identifier for the credential.
status enum (string) (optional) Output only. Current status of the credential.

Possible
values:

- `active`

  The credential is active and valid for use.
- `revoked`

  The credential has been revoked and is no longer valid.
type enum (string) (optional) Required. Output only. The type of credential.

Possible
values:

- `bearer_token`

  Static token injected as header. No refresh logic.
- `oauth2`

  Auto-refresh expired access tokens using stored refresh token.
- `environment_variable`

  Environment variable injected into sandbox container.
update_time string (optional) Output only. The timestamp when the credential was last updated.