Documentation Index
Fetch the complete documentation index at: https://docs.alterauth.com/llms.txt
Use this file to discover all available pages before exploring further.
Overview
This guide covers integrating Alter Vault into an application. By the end, the setup will support:- Connect OAuth accounts and make authenticated API calls
- Use the Python SDK with automatic token injection
- Never handle OAuth tokens directly
Two Types of Credentials
Alter Vault manages two types of credentials. Both use the samevault.request() method -the only difference is where the grant_id comes from.
| OAuth Connections | Managed Secrets | |
|---|---|---|
| What | Third-party services (Google, Slack, GitHub) | Internal APIs (internal services, partner APIs) |
| Who provides credentials | End user authorizes via OAuth flow | Developer stores via Developer Portal |
Where grant_id comes from | Returned in onSuccess callback when user completes Alter Connect | Returned by Developer Portal when you store a secret |
| Setup | Alter Connect UI (frontend) or vault.connect() (headless) | Developer Portal → Managed Secrets → Store Secret |
| Token refresh | Automatic (OAuth refresh flow) | Manual (re-store when rotated) |
The key distinction: For OAuth, the end user triggers the grant by logging into their account (Google, Slack, etc.), and the
grant_id is returned. For Managed Secrets, you (the developer) store the credential in the portal and get the grant_id back. Once you have a grant_id, usage is identical: vault.request(method, url, grant_id=grant_id).Two Integration Paths
| Path | Best for | What you need |
|---|---|---|
| Quick path (below) | CLI tools, scripts, Jupyter notebooks, prototyping | Python only |
| Full web app (Step 4+) | Production web apps with a frontend | Python + JavaScript |
Prerequisites
Before you begin, you’ll need:- An Alter Vault account (sign up free)
- An OAuth app with the chosen provider (Google, GitHub, etc.)
- Python 3.11+
Quick Path: Connect from Python
The fastest way to get started. Everything happens in Python — the SDK opens a browser for the user to authorize, then returns the grant.connect() opens the user’s default browser. Set open_browser=False to print the URL instead (useful for remote servers).Full Web App Integration
For production web apps, use the session-based flow. The backend creates a session and gets back aconnect_url - a hosted page where the user completes OAuth.
Choosing an OAuth Trigger Method
| Method | When to use | How it works |
|---|---|---|
Headless (vault.connect()) | CLI tools, scripts, Jupyter notebooks, backend agents. No frontend at all. | One SDK call does everything — creates a session, opens the user’s default browser, and polls until OAuth completes. Everything happens in Python/TypeScript. |
| Redirect | Server-rendered apps (Django, Rails, etc.), email links, or any app that can redirect a browser. No JavaScript SDK needed. | The backend calls create_connect_session(), gets a connect_url, and redirects the user to it. After OAuth, the user is redirected back to the return_url with the results. |
Popup (@alter-ai/connect SDK) | Single-page apps (React, Vue, etc.) where you want a popup overlay with real-time onSuccess/onError callbacks without leaving the page. | The backend calls create_connect_session() and passes the session_token to the frontend SDK, which opens the hosted page in a popup. |
The frontend JavaScript SDK (
@alter-ai/connect) is optional. The connect_url returned by create_connect_session() is a standard HTTPS URL that works in any browser. The frontend SDK just wraps it in a popup with callbacks for a smoother SPA experience.Key Components
- Python / TypeScript SDK - Backend SDK that creates sessions and makes authenticated API calls via
vault.request() - Alter Connect UI - Hosted page (at the
connect_url) that handles provider selection and the entire OAuth flow - Connect SDK (
@alter-ai/connect) - Optional frontend SDK that opens the hosted page in a popup with callbacks
Step 1: Create an Application
Sign in to the Developer Portal
Go to portal.alterauth.com and sign in
Step 2: Configure the OAuth Provider
Let’s set up Google as an example (other providers work similarly):Go to Google Cloud Console
Navigate to console.cloud.google.com
Create OAuth Credentials
- Go to “APIs & Services” → “Credentials”
- Click “Create Credentials” → “OAuth client ID”
- Choose “Web application”
- Add the Redirect URI from the Developer Portal
Step 3: Install the SDK
Step 4: Create a Session
The backend callscreate_connect_session() which returns:
connect_url- a hosted page where the user completes OAuth (use this for the redirect flow)session_token- a short-lived token to pass to the frontend SDK (use this for the popup flow)
Step 5: Trigger the OAuth Flow
Choose the approach that fits the application:Option A: Redirect Flow (no frontend SDK needed)
Redirect the user’s browser to theconnect_url. After OAuth completes, the user is redirected back to the application. This works with any backend framework - no JavaScript SDK required.
Option B: Popup Flow (frontend SDK)
Use the@alter-ai/connect SDK to open the OAuth page in a popup with real-time callbacks. The user stays on the current page.
Step 6: Use the Python SDK
Now use the SDK to make API calls with automatic token injection:Basic Usage
Using Context Managers
POST Requests and URL Templating
Error Handling
AI Agent Integration
If you’re building AI agents, add actor tracking for full observability:Complete Example: Flask + Google Calendar
Here’s a full example showing a Flask API that fetches calendar events:Alternative: Using Managed Secrets
For internal APIs (internal services, partner APIs, SaaS platforms with API keys), the OAuth flow is not needed. Use Managed Secrets instead.How is this different from OAuth? With OAuth, the
grant_id comes from the end user completing an OAuth login. With Managed Secrets, the grant_id comes from you (the developer) storing a credential in the Developer Portal. No end-user action is needed.Step 1: Store the Secret in the Developer Portal
- Go to the Developer Portal → the application → Managed Secrets
- Click Add Provider (e.g., “Loyalty API”)
- Choose credential type (Bearer Token, API Key, Basic Auth, or AWS SigV4)
- Click Store Secret and enter the credential value
- Copy the
grant_idreturned -this is what gets used in application code
Step 2: Use vault.request()
Use the exact samevault.request() method -just pass the managed secret’s grant_id:
Same security guarantees: Managed secrets get the same zero-exposure encryption, policy enforcement, and audit logging as OAuth tokens. See the Managed Secrets guide for details.
Key Concepts
Zero Token Exposure
vault.request() is the HTTP client -it replaces direct fetch or httpx calls. Instead of constructing auth headers manually, pass a grant_id and the target URL. The SDK:
- Makes the HTTP request on behalf of the caller
- Retrieves the credential internally and injects it as the correct auth header
- Returns the API response directly to you
- Refreshes OAuth tokens transparently before they expire
Where Does grant_id Come From?
Every credential in Alter Vault has a unique grant_id (UUID). Where it originates depends on the credential type:
- OAuth grants: The
grant_idis returned in theonSuccesscallback when the end user completes the OAuth flow via Alter Connect. Store this in the application database, mapped to users. - Managed secrets: The
grant_idis returned by the Developer Portal when a credential is stored. Hard-code it in the config or environment variables.
Multiple Connections (Multi-Account)
A user can connect multiple accounts to the same provider (e.g., personal Gmail + work Gmail). Each connection gets its owngrant_id.
Store the account identifier alongside the grant_id when the user completes Alter Connect:
Provider Support
The SDK works with any OAuth provider configured in the dashboard. Pass thegrant_id as a keyword argument:
Best Practices
Security
- Keep API keys server-side only
- Use session tokens (short-lived) for frontend
- Set IP restrictions in production
Grant Management
- Store the
grant_idfrom Alter Connect in the application database - Map grant IDs to users for easy lookup
- Use
listGrants()to retrieve grant IDs programmatically
Error Handling
- Always handle
PolicyViolationErrorandGrantNotFoundErrorexplicitly - Don’t catch all exceptions with a bare
except Exception - Use retry logic for
NetworkError(with exponential backoff)
Troubleshooting
Grant Not Found
If you getGrantNotFoundError, ensure:
- User has completed OAuth flow via Alter Connect
- The
grant_idis correct and belongs to the application - Connection hasn’t been revoked
Token Expired
The SDK automatically refreshes tokens. If refresh fails:- User may need to re-authenticate
- Check if refresh token has expired
- Verify OAuth app credentials are still valid
Policy Violation
If you getPolicyViolationError:
- Check the error message for the specific rule that failed (time-based access or IP allowlist)
- Review the policy configuration in App Details -> Policies in the Developer Portal
- If using IP allowlist, confirm the server’s IP is included
- If using time restrictions, check if you’re within business hours / weekdays
Provider Not Configured
If you getBackendError with “not configured”:
- Add the provider in the Alter Vault dashboard
- Enter the OAuth Client ID and Client Secret
What’s Next?
Python SDK
Deep dive into the Python SDK with actor tracking
Alter Connect
Customize the OAuth UI
Architecture
Understand the security architecture
Audit Logs
Compliance and observability
Portal Guide
Configure providers and policies
Need Help?
- Email: [email protected]
- Documentation: docs.alterauth.com