---
title: API key connectors in Vercel Connect
description: Understand how API key connectors in Vercel Connect store a provider-issued key and serve it to your code at runtime with getToken.
url: "https://vercel.com/docs/connect/concepts/api-key"
last_updated: 2018-10-20
related:
  - /docs/connect/concepts/tokens
  - /docs/connect
  - /docs/connect/concepts/connectors
  - /docs/connect/concepts/authentication
  - /docs/cli/connect
install_vercel_plugin: npx plugins add vercel/vercel-plugin
search_with_vercel_cli: npx vercel@latest docs search "<query>"
search_kb_with_vercel_cli: npx vercel@latest kb search "<query>"
---

# API key connectors in Vercel Connect

An API key connector lets you store a provider-issued API key in Vercel Connect once and request it at runtime with [`getToken`](/docs/connect/concepts/tokens), so the key stays out of environment variables, source code, prompts, and client bundles. Use it for any provider that authenticates with a static key rather than an OAuth flow.

API key connectors are a [Customer Managed Connector](/docs/connect#connector-ownership-models). You generate the key with the provider, then Vercel stores it encrypted and serves it to your code at runtime. For the full set of connection methods and how API key fits alongside them, see [Connectors](/docs/connect/concepts/connectors).

## What getToken returns for an API key connector

For most connectors, Connect mints a short-lived provider token each time your code calls `getToken`. An API key connector works differently. The access token it returns is the stored key itself, a static credential you supplied, decrypted and handed back to your code.

An OAuth connector produces a fresh, short-lived token per request, whereas an API key connector returns the same stored key every time.

The token response still reports an `expiresAt`. For an API key connector, Connect reports a value at least 15 minutes out. When the key value's own configured expiry is further away, Connect reports that expiry instead. When selecting a key value, Connect honors the request's [validity buffer](/docs/connect/concepts/tokens#caching-and-refresh) and skips stored values that are about to expire.

```ts filename="app/route.ts"
import { getToken } from '@vercel/connect';

const token = await getToken('api-key/my-api', { subject: { type: 'app' } });
// token is the stored API key value, served at runtime
```

## App mode and user mode

An API key connector has a subject type chosen when you create it. It defaults to `app`.

### App mode

In app mode, the connector owner supplies one or more key values at create time. Your code requests a token for the connector itself:

```ts filename="app/route.ts"
import { getToken } from '@vercel/connect';

const token = await getToken('api-key/my-api', { subject: { type: 'app' } });
```

An app-mode connector requires at least one key value when you create it.

### User mode

In user mode, the connector stores no connector-level keys. Each user supplies their own key during [authorization](/docs/connect/concepts/authentication). There is no provider to redirect to, so the authorization screen Vercel hosts collects the key and completes the flow itself.

The connector owner can write Markdown instructions, up to 4,000 characters, shown on that screen to explain how a user obtains a key to paste. The user-supplied key becomes that user's stored credential. A user can supply an expiry for their key. Otherwise Connect treats the key as non-expiring.

Your code requests a token scoped to a specific user:

```ts filename="app/route.ts"
import { getToken, UserAuthorizationRequiredError } from '@vercel/connect';

try {
  const token = await getToken('api-key/my-api', { subject: { type: 'user', id: userId } });
} catch (error) {
  if (error instanceof UserAuthorizationRequiredError) {
    // start an authorization for this user, as with OAuth user flows
  }
}
```

Until a user has supplied a key, `getToken` throws `UserAuthorizationRequiredError`. You start an authorization exactly as you would for an OAuth user flow. See [Tokens](/docs/connect/concepts/tokens) and [Authentication](/docs/connect/concepts/authentication) for the subject types and authorization semantics.

## Multiple key values, scopes, and expiry

An app-mode connector can hold several key values. Each value has an optional `scope` label and an optional expiry.

At request time, pass at most one entry in `scopes`. A request with more than one entry fails. With a scope, Connect returns the active value whose `scope` matches. With no scope, Connect returns the active value that has no scope. Connect skips values whose expiry falls within the current validity buffer. If nothing matches, the request fails with a 401 `unresolved_token` error.

```ts filename="app/route.ts"
import { getToken } from '@vercel/connect';

// returns the active stored value labeled "staging"
const token = await getToken('api-key/my-api', {
  subject: { type: 'app' },
  scopes: ['staging'],
});
```

The `scope` on a key value is a selection label that picks which stored key Connect returns. Connect never sends it to the provider, and it does not narrow what the key can do. A static key keeps whatever authority the provider granted it.

## Rotating key values

You can add, update, and delete key values on an existing connector without recreating it. Updating a value can replace its key, change or remove its scope, and change or remove its expiry. This lets you rotate credentials by adding a new value and deleting the old one while your code keeps calling the same connector.

User-mode connectors hold no connector-level values, so there is nothing to rotate there. Only the instructions shown on the authorization screen are editable.

## What does not apply to API key connectors

Because an API key connector serves a static credential rather than brokering a provider session, several Connect features do not apply:

- **Installations.** API key connectors are single-tenant and have no install flow.
- **Provider-side revocation.** Deleting a key value or the connector removes it from Connect, but the key stays valid at the provider until you revoke it there. This matches the general [revocation semantics](/docs/connect/concepts/tokens) when a provider has no revocation endpoint.
- **Resource indicators and authorization details.** API key connectors do not shape tokens with these, since the credential is static.
- **Secure Compute routing.** API key connectors do not support this setting. See [Secure Compute routing](/docs/connect/concepts/connectors#secure-compute-routing).

## Create an API key connector

You can create an API key connector from the dashboard with **Create Connector**, or from the [Vercel CLI](/docs/cli/connect).

For a generic API, create the connector with the `api-key` slug:

```bash filename="terminal"
vercel connect create api-key --name my-api
```

For a known service that publishes an `api-key` connection method, pass the service name and select the method:

```bash filename="terminal"
vercel connect create <service> --connection-method api-key --name <name>
```

Your code then requests the key by the connector's identifier:

```ts filename="app/route.ts"
import { getToken } from '@vercel/connect';

const token = await getToken('api-key/my-api', { subject: { type: 'app' } });
```

Browse [providers that publish an `api-key` connection method](/connect/browse) to find services with a prebuilt connector. For the end-to-end path, including linking your project, pulling environment variables, and installing the SDK, follow the [Quickstart](/docs/connect/quickstart).

## Security considerations

Vercel Connect encrypts the key at rest, and its management APIs never return the plaintext. Reads report the value as encrypted, so you cannot retrieve a stored key through the API after storing it.

Request the key at runtime with `getToken` instead of persisting it in your own storage. [Project links](/docs/connect/concepts/project-links) control which projects and environments can request a given connector's credential, so scope access by linking only the projects that need it.

## Next steps

- [Connectors](/docs/connect/concepts/connectors): All connection methods and how API key fits among them.
- [Tokens](/docs/connect/concepts/tokens): Subject types, caching, and the validity buffer behind `getToken`.
- [Authentication](/docs/connect/concepts/authentication): How user-mode authorization collects a key.
- [Project links](/docs/connect/concepts/project-links): Control which projects and environments can request a connector.
- [Connector ownership models](/docs/connect#connector-ownership-models): Where API key sits among Customer Managed Connectors.
- [Quickstart](/docs/connect/quickstart): Link a project, pull variables, and request a token end to end.
- [Vercel CLI for Connect](/docs/cli/connect): Discover and create connectors from the command line.
- [Browse connectors](/connect/browse): Providers that publish an `api-key` connection method.

## Search the docs from your terminal

Search the Vercel docs and read pages as Markdown with the Vercel CLI. No login required.

```bash
# Find docs pages by keyword
npx vercel@latest docs search "environment variables"
npx vercel@latest docs search "function timeout"

# Print a docs page as Markdown, by path or URL
npx vercel@latest docs inspect <page>
```

## Search guides from your terminal

Search the Knowledge Base and read guides as Markdown with the Vercel CLI. No login required.

```bash
# Find guides by keyword
npx vercel@latest kb search "rewrites and redirects"
npx vercel@latest kb search "AI SDK streaming"

# Show the latest guides
npx vercel@latest kb

# Print a guide as Markdown, by slug or URL
npx vercel@latest kb inspect <guide>
```

---

[View full sitemap](/docs/sitemap)


If you encounter incorrect information, can’t find what you need, need a capability Vercel doesn’t currently offer, or have any other feedback to report, please do it by following the instructions at https://vercel.com/feedback.md.
