# Welcome to Vaultkit Docs
Source: https://docs.vaultkit.dev/index
From Zero to Agentic Chat with User Data in Minutes.
# Welcome to Vaultkit Docs
Begin your integration with the Vaultkit SDK resources below:
* [Core Concepts](sdk-concepts)
* [Vaultkit SDK Overview](sdk-overview)
* [SDK Quickstart](sdk-quickstart)
* [SDK Configuration](sdk-configuration)
# Backend Integration
Source: https://docs.vaultkit.dev/sdk-backend-integration
Use Vaultkit for internal agents, scheduled jobs, and server-side automation without UI components.
# Backend Integration
Vaultkit isn't just for user-facing applications. You can also use it for:
* **Internal agents** (backend services that act on behalf of users)
* **Scheduled jobs** (automated tasks that need to call external APIs)
* **Multi-tenant systems** (per-user vault provisioning on the server)
The key difference from user-facing flows is that there's no UI component layer—you're managing vaults and connections directly.
## Pre-configured vaults (simplest)
If you have a static vault already set up in the Vaultkit dashboard, you can connect directly without any UI. For an introduction to vaults and how they work, see [Core Concepts](sdk-concepts#vault).
```ts theme={null}
import { createVaultkitClient } from "@vaultkit/ai-sdk";
// Backend service connecting to a pre-configured vault
const vaultkit = createVaultkitClient({
apiKey: process.env.VAULTKIT_API_KEY,
userId: "user_123", // the end user this action is on behalf of
vaultId: "vault_abc123", // your pre-configured vault
});
await vaultkit.connect();
// vaultkit.tools is now ready to use with your LLM or directly
console.log(`Connected. Found ${vaultkit.tools.length} tools.`);
// Use tools directly or pass to your LLM runtime
const result = await vaultkit.tools[0].execute({ /* params */ });
```
## Dynamic vault provisioning (per-user)
For multi-tenant systems where each user gets their own vault, use feature mappings:
```ts theme={null}
import { createVaultkitClient } from "@vaultkit/ai-sdk";
async function provisionUserVault(userId: string) {
const vaultkit = createVaultkitClient({
apiKey: process.env.VAULTKIT_API_KEY,
userId: userId,
featureMappingId: "feat_internal_automation", // your feature template
});
await vaultkit.connect();
// Vaultkit automatically created/found a vault for this user
return vaultkit.tools;
}
```
The first time a user connects, Vaultkit creates a vault from the feature mapping. Subsequent calls reuse the existing vault.
## Restricting providers and scopes
You can further limit which providers or permissions a vault has:
```ts theme={null}
const vaultkit = createVaultkitClient({
apiKey: process.env.VAULTKIT_API_KEY,
userId: "user_456",
featureMappingId: "feat_automation",
selectedProviders: ["gmail", "slack"], // only enable these two
selectedScopes: ["read"], // read-only access
});
await vaultkit.connect();
```
This is useful for:
* **Least privilege**: Only enable the providers a job actually needs
* **Customer restrictions**: Limit what an agent can do for a particular user
* **Testing**: Create isolated vaults with limited permissions
## Example: Scheduled email automation
```ts theme={null}
import { createVaultkitClient } from "@vaultkit/ai-sdk";
import { generateText } from "ai";
import { openai } from "@ai-sdk/openai";
async function dailyEmailDigest(userId: string) {
// Get tools for this user's vault
const vaultkit = createVaultkitClient({
apiKey: process.env.VAULTKIT_API_KEY,
userId: userId,
vaultId: "vault_email_digest", // pre-configured vault for this job
});
await vaultkit.connect();
// Use with Vercel AI SDK to generate an email
const { text } = await generateText({
model: openai("gpt-4"),
tools: vaultkit.tools,
prompt: "Create a daily digest of unread emails and send a summary.",
});
console.log(`Digest sent for user ${userId}`);
return text;
}
// Run daily via cron, GitHub Actions, etc.
await dailyEmailDigest("user_789");
```
## Error handling
Backend flows should handle disconnections and retries:
```ts theme={null}
import { AuthenticationError, ConnectionError } from "@vaultkit/ai-sdk";
try {
const vaultkit = createVaultkitClient({
apiKey: process.env.VAULTKIT_API_KEY,
userId: userId,
vaultId: vaultId,
retries: 5, // more retries for reliability
timeout: 60000, // longer timeout for batch jobs
});
await vaultkit.connect();
} catch (error) {
if (error instanceof AuthenticationError) {
console.error("Invalid API key or vault ID");
// Handle auth failure (don't retry)
} else if (error instanceof ConnectionError) {
console.error("Network error - may retry");
// Retry logic here
}
}
```
## Logging and observability
For backend services, enable detailed logging:
```ts theme={null}
const vaultkit = createVaultkitClient({
apiKey: process.env.VAULTKIT_API_KEY,
userId: userId,
vaultId: vaultId,
log: (level, message, data) => {
// Send to your observability stack (DataDog, New Relic, etc.)
console.log(`[vaultkit:${level}] ${message}`, data);
},
});
```
## No UI components needed
Backend flows don't use `FeatureSelect`, `AuthComponent`, or `VaultkitProvider`. Manage everything programmatically with `createVaultkitClient` directly.
For more configuration options, see [SDK Configuration](sdk-configuration).
# Core Concepts
Source: https://docs.vaultkit.dev/sdk-concepts
Learn the key Vaultkit primitives—features, vaults, tools, providers, and approvals—before wiring the SDK into your product.
# Core Concepts
Vaultkit’s SDK mirrors the same objects you configure in the dashboard. Understanding how they fit together helps you reason about what the UI components render and which credentials your agent receives.
## Feature
A **feature** is the customer-facing bundle you expose in your product (for example “Email assistant”). Features are created in the dashboard and include:
* A title and description your end users recognize.
* The list of **providers** (integrations) required for that capability.
* The scopes/permissions each provider needs.
* An optional connection to a specific vault (static mode) or instructions for generating one per user (dynamic mode).
`FeatureSelect` surfaces these features so end users can opt into the flows they need.
## Provider
A **provider** represents an external service (Gmail, Outlook, Slack, GitHub, etc.) exposed through Vaultkit. Providers are attached to features and vaults, and they determine which OAuth buttons appear in `AuthComponent`.
## Vault
A **vault** is a per-user configuration that defines which providers and tools are available to your agent. Think of it as a permission set—it specifies what providers (Gmail, Slack, etc.) the user has connected and what tools the agent is allowed to call on their behalf.
Vaults can be created two ways:
* **Static** – One vault with a fixed set of providers. You create this in the dashboard and reuse the same vault ID across multiple users. Best for internal agents and backend services where all users need the same set of tools. For example, a scheduled email job might have a vault with just Gmail connected.
* **Dynamic** – One vault per user, created automatically when they enable a feature. Best for user-facing apps where different users might select different providers.
**Note:** Features are optional. They exist to help app builders organize which providers are available to users. For internal agents, you can skip features entirely and create a vault directly with whatever providers you need.
When `createVaultkitClient()` connects, it looks up the vault, verifies which providers are connected, and returns the list of available tools your agent can call.
## Tool
A **tool** is an executable action (usually proxied through Composio) that your agent can call, such as “Send Gmail message” or “Create GitHub issue.” Tools are attached to vaults; when `createVaultkitClient().connect()` runs, it returns the list of tools the agent is allowed to use. These map directly onto the tool schema you pass into the Vercel AI SDK or another LLM runtime.
## Approval *(coming soon)*
An **approval** is a human-in-the-loop gate on a tool. This capability is on our roadmap; when released, the dashboard will let you flag sensitive tools, the SDK will raise an `ApprovalError` until an operator decides, and telemetry will record each decision. For now, treat approvals as a planned enhancement.
## How they relate
```text theme={null}
Feature (Email assistant)
├── Providers: Gmail, Outlook
├── Scopes: read, send, delete
└── Vault(s)
├── Static vault (shared) or dynamic per end user
└── Tools (Send email, Draft reply, Archive thread)
```
1. You define the feature and its providers in the dashboard.
2. End users enable the feature via `FeatureSelect` and authenticate each provider through `AuthComponent`.
3. The SDK resolves the vault tied to that feature/user and exposes the tool list to your agent.
4. Approvals and telemetry keep humans in control of sensitive actions.
Keep this mental model handy while building—every SDK call maps back to these primitives.
# SDK Configuration
Source: https://docs.vaultkit.dev/sdk-configuration
Explore every option supported by createVaultkitClient and how to tailor the connection to your needs.
# SDK Configuration
`createVaultkitClient` accepts a `VaultkitConfig` object. Use it to control authentication, timeouts, retries, logging, and the way dynamic vaults are generated.
## Required properties
Always provide these three values when creating a client:
| Property | Type | Description |
| --------------------------------- | -------- | ------------------------------------------------------------------------------- |
| `apiKey` | `string` | Your Vaultkit API key (represents your organization). |
| `userId` | `string` | Identifier for the end user the agent is acting on behalf of. |
| `vaultId` *or* `featureMappingId` | `string` | Either a static vault ID, or a dynamic vault template ID. Only one is required. |
> **About static vs. dynamic vaults:**
>
> * Use `vaultId` if you have a pre-configured vault in the Vaultkit dashboard.
> * Use `featureMappingId` to generate vaults on demand. Vaultkit will create a per-user vault the first time `connect()` is called.
## Optional properties
Fine-tune behavior with these optional settings:
| Property | Type | Default | Purpose |
| ------------------- | --------------------------------- | -------------------------- | --------------------------------------------------------------------------------------------------------------------- |
| `selectedProviders` | `string[]` | `undefined` | Restrict which providers to activate for dynamic vaults. Must be a subset of the feature mapping's providers. |
| `selectedScopes` | `string[]` | `undefined` | Further limit provider permissions for dynamic vaults. |
| `timeout` | `number` | `30000` | Timeout (ms) for discovery requests made during `connect()`. |
| `retries` | `number` | `3` | Retry attempts for transient network failures. |
| `baseUrl` | `string` | `https://app.vaultkit.dev` | Only set this if using a self-hosted or custom Vaultkit instance. Default points to production. |
| `log` | `(level, message, data?) => void` | Lightweight console logger | Receive verbose status messages (`info`, `warn`, `error`). Useful for piping diagnostics to your observability stack. |
## Example: Interactive flow (recommended)
This is the typical flow for apps with user-facing UIs. Users select features and authenticate providers through the SDK UI components, then you create a client with the resulting vault.
```ts theme={null}
import { createVaultkitClient } from "@vaultkit/ai-sdk";
// After user has selected a feature via FeatureSelect UI
// and authenticated providers via AuthComponent
const vaultkit = createVaultkitClient({
apiKey: process.env.VAULTKIT_API_KEY!,
userId: currentUser.id,
vaultId: userSelectedVault.id, // from FeatureSelect UI state
});
await vaultkit.connect();
```
## Example: Programmatic flow (advanced)
Use this only when you need to dynamically provision vaults server-side without user interaction.
```ts theme={null}
import { createVaultkitClient } from "@vaultkit/ai-sdk";
// Backend agent or automation service that provisions vaults on demand
const vaultkit = createVaultkitClient({
apiKey: process.env.VAULTKIT_API_KEY!,
userId: targetUser.id,
featureMappingId: "feat_customer_support", // pre-configured feature template
selectedProviders: ["gmail", "slack"], // optional: restrict providers
selectedScopes: ["read", "write"], // optional: restrict permissions
timeout: 45_000, // optional: increase for slower networks
retries: 5, // optional: more retries for unreliable connections
log: (level, message, meta) => {
console[level]("[vaultkit]", message, meta ?? "");
},
});
await vaultkit.connect();
```
## Example: Backend/Internal agent (no UI)
For internal services and scheduled jobs, use pre-configured vaults without any UI components:
```ts theme={null}
import { createVaultkitClient } from "@vaultkit/ai-sdk";
// Scheduled job or internal service
// No user interaction, just programmatic access
const vaultkit = createVaultkitClient({
apiKey: process.env.VAULTKIT_API_KEY!,
userId: "user_to_act_on_behalf_of",
vaultId: "vault_daily_digest", // pre-configured in dashboard
retries: 5, // higher retries for batch jobs
timeout: 60_000, // longer timeout
});
await vaultkit.connect();
// vaultkit.tools is now ready to use
```
For more details on backend integration patterns, see [Backend Integration](sdk-backend-integration).
## Inspecting the client
`createVaultkitClient` returns a small API:
* `vaultkit.tools` – Getter that exposes the array of Vaultkit tools after `connect()` succeeds.
* `await vaultkit.connect()` – Resolves the correct vault and fetches tools. It also handles dynamic provisioning when `featureMappingId` is present.
* `await vaultkit.disconnect()` – Clears in-memory tool state. Call this in `finally` blocks to avoid leaking resources.
If you need to share discovery results across multiple requests (for example in a long-lived worker), keep the client in a module-level cache and call `connect()` once during startup.
# Dynamic Vault Provisioning
Source: https://docs.vaultkit.dev/sdk-dynamic-vaults
Generate per-user vaults on demand using feature mappings and the Vaultkit SDK.
# Dynamic Vault Provisioning
Dynamic vaults let you expose a single feature to customers while Vaultkit quietly provisions a dedicated vault for each end user. This keeps credentials scoped and auditable without leaking internal IDs to your integrators.
## How it works
1. Configure a **feature mapping** in the Vaultkit dashboard ([Dashboard → Feature Mappings](https://app.vaultkit.dev/dashboard/features)) in either static or dynamic mode. Set the feature name, description, providers (for example Gmail, Outlook), and the scopes each provider requires. This metadata is what `FeatureSelect` and `AuthComponent` render to end users.
2. Pass the mapping’s ID to the SDK via `featureMappingId`.
3. When `connect()` runs, the SDK checks whether a vault already exists for the end user.
* If it exists, the SDK reuses it and loads the available tools.
* If not, it calls `POST /api/vaultkit/generate-vault`, creates a vault with the permitted providers and scopes, and returns the new ID.
4. Tool discovery continues as normal and your agent receives the merged toolset.
## Basic implementation
```ts theme={null}
import { createVaultkitClient } from "@vaultkit/ai-sdk";
const vaultkit = createVaultkitClient({
apiKey: process.env.VAULTKIT_API_KEY!,
userId: customer.id,
featureMappingId: "feat_github_triage",
});
await vaultkit.connect();
```
## Limiting providers and scopes
Dynamic mappings can allow multiple providers. If you want to capture user intent at runtime (for example GitHub **and** Slack vs. GitHub only), pass the user’s selection to the SDK.
```ts theme={null}
const vaultkit = createVaultkitClient({
apiKey: env.VAULTKIT_API_KEY,
userId: customer.id,
featureMappingId: "feat_dynamic_support",
selectedProviders: customer.selectedProviders,
selectedScopes: customer.selectedScopes,
});
```
The SDK enforces that the requested providers/scopes are subsets of what the feature mapping allows. Anything outside that set results in an `AuthenticationError`.
## Persisting generated vaults
The SDK exposes everything it learns while provisioning:
```ts theme={null}
const vault = await vaultkit.connect();
console.log(
"Resolved vault ID:",
vaultkit.tools.length ? vaultkit.tools[0].vaultId : "(in tools metadata)"
);
```
If you need to surface the generated vault ID elsewhere (for example to show in your admin tools), listen to the responses from your own API layer. The Vaultkit REST API returns `generated_vault_id` in the payload from `/api/vaultkit/generate-vault`.
## Pair with the Feature Selection component
`FeatureSelection` (exported from `@vaultkit/ai-sdk`) gives end users a UI for choosing which features and providers to enable. It writes the user’s choices into the shared context so you can feed them into the client before calling `connect()`.
```tsx theme={null}
import { FeatureSelection, VaultkitProvider, useVaultkit } from "@vaultkit/ai-sdk";
function FeatureStep() {
const { selectedFeatures, getSelectedProviders } = useVaultkit();
// Use these helpers to populate selectedProviders / selectedScopes when connecting
return
{JSON.stringify({ selectedFeatures: Array.from(selectedFeatures), featureProviders, connections }, null, 2)}
);
}
```
Use these helpers to pass `selectedProviders`/`selectedScopes` into `createVaultkitClient` before your agent connects.