Credential Vault and Auth Framework for AI Agents

0.8.2 · active · verified Wed Apr 22

agent.pw is a robust credential vault and authentication framework specifically designed for AI agents. It provides secure storage for encrypted credentials, including OAuth tokens and API keys, utilizing AES-GCM for data at rest. The library manages the entire OAuth lifecycle, supporting PKCE, token refresh, revocation, and RFC 9728 discovery. Currently at version 0.8.2, the project exhibits a rapid release cadence with frequent patch and minor updates (multiple in April 2026 alone), indicating active development and continuous improvement. Key differentiators include its agent-centric design, comprehensive OAuth handling, support for admin-configurable credential profiles, path-based organization (`ltree` paths like `acme.connections.github`), and scoped access control. It is designed to be embeddable, working seamlessly with any PostgreSQL-compatible database without requiring a separate server component.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize `agent.pw` with a PostgreSQL database, an encryption key, and an in-memory OAuth flow store, then resolves headers for a resource.

import { createAgentPw } from "agent.pw";
import { createInMemoryFlowStore } from "agent.pw/oauth";
import { createDb } from "agent.pw/sql";
import { unwrap } from "okay-error";

async function initializeAgentPw() {
  const databaseUrl = process.env.DATABASE_URL ?? '';
  if (!databaseUrl) {
    throw new Error("DATABASE_URL environment variable is required.");
  }
  const encryptionKey = process.env.AGENTPW_ENCRYPTION_KEY ?? '';
  if (!encryptionKey) {
    throw new Error("AGENTPW_ENCRYPTION_KEY environment variable is required.");
  }

  const db = unwrap(createDb(databaseUrl));
  const agentPw = await unwrap(
    createAgentPw({
      db,
      encryptionKey,
      flowStore: createInMemoryFlowStore(),
    }),
  );

  console.log('agent.pw initialized successfully.');
  
  // Example: Resolve headers for a previously connected resource
  const path = "acme.connections.docs"; // Replace with your resource path
  try {
    const headers = await unwrap(agentPw.connect.resolveHeaders({ path }));
    console.log(`Resolved headers for ${path}:`, headers);
  } catch (error) {
    console.error(`Failed to resolve headers for ${path}:`, error);
  }
  
  return agentPw;
}

initializeAgentPw().catch(console.error);

view raw JSON →