[**@vercel/oidc**](../README.md)

---

# Function: getVercelOidcToken()

> **getVercelOidcToken**(`options?`): [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<`string`\>

Defined in: [packages/oidc/src/get-vercel-oidc-token-with-refresh.ts:100](https://github.com/vercel/vercel/blob/main/packages/oidc/src/get-vercel-oidc-token-with-refresh.ts#L100)

Gets the current OIDC token from the request context, the Vercel OIDC token
file, or the environment variable.

Do not cache this value, as it is subject to change in production!

It checks for the `x-vercel-oidc-token` header in the request context, then
reads the file named by `VERCEL_OIDC_TOKEN_FILE` when set, then falls back to
the `VERCEL_OIDC_TOKEN` environment variable.

Unlike the `getVercelOidcTokenSync` function, this function will refresh the token if it is expired in a development environment.

## Parameters

### options?

`GetVercelOidcTokenOptions`

Optional configuration for token retrieval.

## Returns

[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<`string`\>

A promise that resolves to the OIDC token.

## Throws

If no token source is available or the configured file cannot be read. If the token
is expired in a development environment, will also throw an error if the token cannot be refreshed: no CLI credentials are available, CLI credentials are expired, no project configuration is available
or the token refresh request fails.

## Examples

```js
// Using the OIDC token
getVercelOidcToken()
  .then(token => {
    console.log('OIDC Token:', token);
  })
  .catch(error => {
    console.error('Error:', error.message);
  });
```

```js
// Using the OIDC token with explicit team and project (supports IDs and slugs)
getVercelOidcToken({ team: 'my-team', project: 'my-project' })
  .then(token => {
    console.log('OIDC Token:', token);
  })
  .catch(error => {
    console.error('Error:', error.message);
  });
```
