> ## AI Agent Context > Get the complete documentation index at: https://aistudio.google.com/llms.txt > Use this file to discover all available pages. > For the full documentation in a single file, fetch: https://aistudio.google.com/llms-full.txt # Creating a credential {% callout type="note" %} This API is in Beta. Endpoints are under `/v1beta/`. {% /callout %} {% mark class="http-post" %}{% icon name="north_east" /%}`POST`{% /mark %} `https://generativelanguage.googleapis.com/v1beta/credentials` Creates a new credential. {% two-column-layout %} {% left-column %} ## Request Body {% class="hide-from-toc" id="request-body" %} {% section class="api-ref-property-list" %} The request body structure depends on the interaction mode: {% details %} {% summary %} **EnvironmentVariableConfig** {% /summary %} Configuration for environment variable credentials. **value**: {% mark %}required{% /mark %} `string` Input only. Secret value of the environment variable. Write-only; never returned in responses. {% hr /%} {% details %} {% summary %} **injection_location**: {% mark %}required{% /mark %} `InjectionLocation` or `InjectionLocation array` 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. {% /summary %} **Possible Types:** {% class="api-ref-label" %} {% details %} {% summary %} **InjectionLocation** {% /summary %} Possible values: - `header`: Injected into HTTP request headers. - `query`: Injected into HTTP URL query parameters. - `body`: Injected into HTTP request body. {% /details %} {% details %} {% summary %} **InjectionLocation array** {% /summary %} Possible values: - `header`: Injected into HTTP request headers. - `query`: Injected into HTTP URL query parameters. - `body`: Injected into HTTP request body. {% /details %} {% /details %} {% hr /%} **id**: {% mark %}required{% /mark %} `string` {% hr /%} **type**: {% mark %}required{% /mark %} `object` Value: `environment_variable` {% hr /%} **trusted_domains**: `string array` Optional. List of domains allowed to receive this environment variable value in HTTP requests. {% /details %} {% details %} {% summary %} **HttpBearerConfig** {% /summary %} Configuration for HTTP Bearer token credentials. **token**: {% mark %}required{% /mark %} `string` Input only. The static bearer token. Write-only; never returned in responses. {% hr /%} **id**: {% mark %}required{% /mark %} `string` {% hr /%} **type**: {% mark %}required{% /mark %} `object` Value: `bearer_token` {% hr /%} **header_name**: `string` Optional. Header name to inject the token into. Defaults to 'Authorization'. {% hr /%} **prefix**: `string` Optional. Prefix to prepend to the token. Defaults to 'Bearer'. Set to '' for no prefix. {% /details %} {% details %} {% summary %} **OAuth2Config** {% /summary %} Configuration for OAuth2 credentials with automatic token refresh. **client_id**: {% mark %}required{% /mark %} `string` OAuth2 client ID. {% hr /%} **client_secret**: {% mark %}required{% /mark %} `string` Input only. OAuth2 client secret. Write-only; never returned in responses. {% hr /%} **refresh_token**: {% mark %}required{% /mark %} `string` Input only. OAuth2 refresh token. Write-only; never returned in responses. {% hr /%} **token_url**: {% mark %}required{% /mark %} `string` OAuth2 token endpoint URL for refreshing access tokens. {% hr /%} **id**: {% mark %}required{% /mark %} `string` {% hr /%} **type**: {% mark %}required{% /mark %} `object` Value: `oauth2` {% hr /%} **scopes**: `string array` Optional. List of OAuth2 scopes. {% /details %} {% /section %} {% /left-column %} {% right-column class="sticky" %} **Example request** {% class="example-heading" %} {% tabs %} {% tab label="REST" %} ```sh curl -X POST "https://generativelanguage.googleapis.com/v1beta/credentials" \ -H "x-goog-api-key: $GEMINI_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "value": "string", "injection_location": "header", "id": "string", "type": "environment_variable" }' ``` {% /tab %} {% /tabs %} {% /right-column %} {% /two-column-layout %} {% two-column-layout %} {% left-column %} ## Response {% class="hide-from-toc" id="response" %} {% section class="api-ref-property-list" %} **id**: {% mark %}required{% /mark %} `string` Output only. Identifier. Unique identifier for the credential. {% hr /%} {% details %} {% summary %} **type**: {% mark %}required{% /mark %} `string enum` Output only. The type of credential. {% /summary %} 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. {% /details %} {% hr /%} {% details %} {% summary %} **status**: `string enum` Output only. Current status of the credential. {% /summary %} Possible values: - `active`: The credential is active and valid for use. - `revoked`: The credential has been revoked and is no longer valid. {% /details %} {% hr /%} **create_time**: `string` Output only. The timestamp when the credential was created. {% hr /%} **update_time**: `string` Output only. The timestamp when the credential was last updated. {% /section %} {% /left-column %} {% right-column class="sticky" %} **Example response** {% class="example-heading" %} ```json { "id": "string", "type": "bearer_token", "status": "active", "create_time": "string", "update_time": "string" } ``` {% /right-column %} {% /two-column-layout %}