> ## Documentation Index
> Fetch the complete documentation index at: https://auth0.com/ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Call Third-Party APIs on User's Behalf

> Enable your AI agent to call third-party APIs on the user's behalf with Token Vault.

A third-party API is owned and operated by an external organization, such as Google, Slack, or GitHub.

The user can grant your AI agent permission to access a third-party API on their behalf using [Token Vault](https://auth0.com/docs/secure/call-apis-on-users-behalf/token-vault). When a user connects with an external provider and authorizes access, Auth0 stores the provider's tokens in Token Vault. The agent then performs a token exchange to retrieve an external access token scoped to the permissions the user has granted.

## How it works

Token Vault supports the following token exchange patterns depending on your application type.

### Refresh token exchange

Use the refresh token exchange when your application can obtain Auth0 refresh tokens, such as web, mobile, or native applications. This allows the agent to call external APIs even when the user is not actively using the application.

<Frame caption="Token Vault using Refresh Tokens">
  <img className="hidden dark:block" src="https://mintlify.s3.us-west-1.amazonaws.com/auth0-genai/img/intro/authentication_for_users_of_ai_applications_diagram_dark.png" alt="Token Vault using Refresh Tokens" />

  <img className="block dark:hidden" src="https://mintlify.s3.us-west-1.amazonaws.com/auth0-genai/img/intro/authentication_for_users_of_ai_applications_diagram_light.png" alt="Token Vault using Refresh Tokens" />
</Frame>

<Steps>
  <Step title="User connects external provider">
    The user logs in and authorizes access to an external provider (e.g., Google) via the [Connected Accounts flow](https://auth0.com/docs/secure/call-apis-on-users-behalf/token-vault/connected-accounts-for-token-vault). Auth0 stores the provider's access and refresh tokens in Token Vault.
  </Step>

  <Step title="Agent requests external access token">
    When the agent needs to call the external API, it performs a refresh token exchange — passing the Auth0 refresh token to the `/oauth/token` endpoint to retrieve the external provider's access token from Token Vault.
  </Step>

  <Step title="Token Vault returns external access token">
    Auth0 validates the refresh token, locates the stored external token, and returns the external provider's access token to the agent.
  </Step>

  <Step title="Agent calls the external API">
    The agent uses the external access token to call the third-party API on the user's behalf and returns the response to the user.
  </Step>
</Steps>

<Callout icon="file-lines" color="#0EA5E9" iconType="regular">
  If your application uses [Organizations](https://auth0.com/docs/manage-users/organizations), authenticate the user with the target organization before authorizing the external provider through Connected Accounts. Organizations determine the session context, but Token Vault still exchanges tokens for the individual signed-in user.
</Callout>

### Access token exchange

Use the access token exchange when your application cannot obtain refresh tokens, such as Single-Page Applications (SPAs) or headless agents and CLIs. The backend API performs the token exchange using a Custom API Client linked to itself.

<Frame caption="Token Vault using Access Tokens">
  <img className="hidden dark:block" src="https://mintlify.s3.us-west-1.amazonaws.com/auth0-genai/img/intro/web_applications_with_spa_diagram_dark.png" alt="Token Vault using Access Tokens" />

  <img className="block dark:hidden" src="https://mintlify.s3.us-west-1.amazonaws.com/auth0-genai/img/intro/web_applications_with_spa_diagram_light.png" alt="Token Vault using Access Tokens" />
</Frame>

<Steps>
  <Step title="User connects external provider">
    The user logs in and authorizes access to an external provider via the [Connected Accounts flow](https://auth0.com/docs/secure/call-apis-on-users-behalf/token-vault/connected-accounts-for-token-vault). Auth0 stores the provider's tokens in Token Vault.
  </Step>

  <Step title="SPA calls backend API with Auth0 access token">
    The SPA passes the Auth0 access token in the `Authorization` header when calling the backend API. The backend validates the token's signature, issuer, audience, expiration, and scopes.
  </Step>

  <Step title="Backend performs access token exchange">
    The backend uses a Custom API Client — configured with the same identifier as the backend API — to exchange the Auth0 access token for the external provider's access token via the `/oauth/token` endpoint.
  </Step>

  <Step title="Token Vault returns external access token">
    Auth0 validates the request, locates the stored external token, and returns the external provider's access token to the backend.
  </Step>

  <Step title="Agent calls the external API">
    The backend uses the external access token to call the third-party API on the user's behalf and returns the response to the user.
  </Step>
</Steps>

## Connections

Auth0 supports popular social and enterprise external providers such as Google, GitHub, Slack, and more. Once the user logs in and authorizes access to the external provider, their account is added to Auth0 as a Token Vault connection.

With Token Vault, AI agents can securely access external (third-party) APIs through authorized connections to perform tasks on the user's behalf, such as:

* Reading a user's Google calendar to schedule a meeting.
* Accessing a user's Microsoft documents to summarize them.
* Connecting to a CRM like Salesforce to retrieve customer information.

<Card title="View All Connections" href="/ai/docs/integrations/overview" icon="share-nodes" horizontal />

## Get started

To begin using Token Vault with your AI agents, refer to the following resources:

### Quickstarts

<Columns cols={2}>
  <Card title="Call Other's APIs on User's Behalf" href="/ai/docs/get-started/call-others-apis-on-users-behalf" icon="key" horizontal />
</Columns>

### Guides

<Columns cols={2}>
  <Card title="Check Google Calendar Availability" href="/ai/docs/how-tos/check-google-calendar-availability" icon="calendar" horizontal />

  <Card title="List GitHub Repositories" href="/ai/docs/how-tos/list-github-repositories" icon="github" horizontal />

  <Card title="List Slack Channels" href="/ai/docs/how-tos/list-slack-channels" icon="slack" horizontal />

  <Card title="Get Salesforce Opportunities" href="/ai/docs/how-tos/get-salesforce-opportunities" icon="salesforce" horizontal />
</Columns>

### Sample Apps

<Columns cols={2}>
  <Card
    title="Assistant0: Next.js + LangGraph"
    href="https://github.com/auth0-samples/auth0-assistant0/tree/main/ts-langchain"
    icon={
  <img
    src="https://mintlify-assets.b-cdn.net/auth0/langchain.svg"
    alt="LangChain"
  />
}
    horizontal
  />

  <Card
    title="Assistant0: Next.js + Vercel AI SDK"
    href="https://github.com/auth0-samples/auth0-assistant0/tree/main/ts-vercel-ai"
    icon={
  <img
    src="https://mintlify-assets.b-cdn.net/auth0/vercel.svg"
    alt="Vercel AI"
  />
}
    horizontal
  />

  <Card
    title="Assistant0: FastAPI + LangGraph"
    href="https://github.com/auth0-samples/auth0-assistant0/tree/main/py-langchain"
    icon={
  <img
    src="https://mintlify-assets.b-cdn.net/auth0/langchain.svg"
    alt="LangChain"
  />
}
    horizontal
  />

  <Card
    title="Assistant0: Next.js + LlamaIndex"
    href="https://github.com/auth0-samples/auth0-assistant0/tree/main/ts-llamaindex"
    icon={
  <img
    src="https://mintlify-assets.b-cdn.net/auth0/llamadex.svg"
    alt="LlamaIndex"
  />
}
    horizontal
  />

  <Card
    title="Assistant0: FastAPI + LlamaIndex"
    href="https://github.com/auth0-samples/auth0-assistant0/tree/main/py-llamaindex"
    icon={
  <img
    src="https://mintlify-assets.b-cdn.net/auth0/llamadex.svg"
    alt="LlamaIndex"
  />
}
    horizontal
  />

  <Card title="Auth0 AI SDK TypeScript samples" href="https://github.com/auth0/auth0-ai-js/tree/main/examples/calling-apis" icon="github" horizontal />

  <Card title="Auth0 AI SDK Python samples" href="https://github.com/auth0/auth0-ai-python/tree/main/examples/calling-apis" icon="github" horizontal />
</Columns>

### Learn more

<Columns cols={2}>
  <Card title="Configure Token Vault" href="https://auth0.com/docs/secure/call-apis-on-users-behalf/token-vault/configure-token-vault" icon="gear" horizontal />

  <Card title="Refresh Token Exchange with Token Vault" href="https://auth0.com/docs/secure/call-apis-on-users-behalf/token-vault/refresh-token-exchange-with-token-vault" icon="key" horizontal />

  <Card title="Access Token Exchange with Token Vault" href="https://auth0.com/docs/secure/call-apis-on-users-behalf/token-vault/access-token-exchange-with-token-vault" icon="key" horizontal />
</Columns>
