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

# API Connections

> Connect external services to your app with managed or custom API keys.

**API Connections** let you integrate external services into your app—like AI models, payment processors, analytics tools, and more. Bloom can automatically provide and manage API keys for you, or you can bring your own.

## Why API connections matter

Most modern apps rely on external services:

> [card] AI & Machine Learning
>
> Connect to services like Google AI, OpenAI, or Anthropic to add smart features—chatbots, content generation, image analysis, etc.

> [card] Payments
>
> Integrate Stripe, PayPal, or other payment processors to accept payments in your app.

> [card] Analytics
>
> Track user behavior and app performance with services like Mixpanel, Segment, or Google Analytics.

> [card] Communication
>
> Send emails (SendGrid, Mailgun), SMS messages (Twilio), or push notifications (Firebase).

> [!NOTE]
>
> API keys are like passwords that let your app talk to external services securely. Bloom helps you manage them safely.

## Auto-provisioned API keys

Bloom can **automatically provide API keys** for popular services, so you can start using them immediately without creating accounts or managing credentials yourself.

### How it works

> [tab] Enabled (Recommended)
>
> **When auto-provisioning is ON:**
>
> > [!TIP]
> >
> > Bloom provides API keys automatically for supported services
>
> > [!TIP]
> >
> > Keys are securely managed and rotated by Bloom
>
> > [!TIP]
> >
> > Usage counts against your plan's credits
>
> > [!TIP]
> >
> > No need to create external accounts or manage credentials
>
> > [!TIP]
> >
> > Start using services immediately
>
> > [!TIP]
> >
> > This is the fastest way to add external services to your app—perfect for development, testing, and most production use cases.
>
> **Supported services:**
>
> * Google AI (Gemini models)
>
> * Additional services coming soon
>
> > [!NOTE]
> >
> > Auto-provisioned keys are shared across your Bloom apps but isolated per project for security.

> [tab] Disabled
>
> **When auto-provisioning is OFF:**
>
> > [!TIP]
> >
> > You provide your own API keys for each service
>
> > [!TIP]
> >
> > Full control over API accounts and billing
>
> > [!TIP]
> >
> > Direct access to service dashboards and logs
>
> > [!TIP]
> >
> > Required for services not supported by Bloom provisioning
>
> > [!NOTE]
> >
> > You'll need to create accounts with each external service, generate API keys, and add them as environment variables in Bloom.
>
> **When to disable auto-provisioning:**
>
> * You need specific API quotas or rate limits
> * You want direct billing from the service provider
> * You're using services not yet supported by Bloom provisioning
> * Your organization requires managing all API credentials directly

### Credit usage warning

> [!WARNING]
>
> **API provisioning disabled - insufficient credits**
>
> Your Bloom credits have been exhausted. API calls will fail until you upgrade your plan or disable API provisioning.

If you see this warning:

1. **Upgrade your plan** to get more credits (recommended for continued use)
2. **Disable API provisioning** and use your own API keys instead
3. **Purchase credit top-ups** from your billing dashboard

> [card] [View plans and pricing](https://docs.bloom.diy/pricing-and-credits.md)
>
> Compare plans and see how credits are used

## Environment Variables

Environment variables let you securely store API keys, configuration values, and other sensitive information your app needs to function.

### What are environment variables?

Think of environment variables as a secure storage locker for your app's secrets:

* **API keys** from external services
* **Configuration values** like feature flags or URLs
* **Credentials** for databases or third-party services

They're called "environment" variables because they're specific to where your app is running (development vs. production) and kept separate from your code.

> [!NOTE]
>
> Environment variables are **never exposed** in your app's frontend code or shared publicly. They're only accessible from your backend functions.

### Managing variables

**1. Click 'Add Variable'**

Opens a form to create a new environment variable.

**2. Enter variable details**

* **Name:** What you'll call this variable in your code (e.g., `STRIPE_API_KEY`)
* **Value:** The actual key or configuration value

> [!TIP]
>
> Use UPPERCASE\_WITH\_UNDERSCORES for variable names—it's a common convention that makes them easy to identify.

**3. Save the variable**

The variable is immediately available in your Convex backend functions.

**4. Use it in your code**

Access the variable in your backend using `process.env.VARIABLE_NAME`

```ts theme={null}
// Example: Using an API key in a Convex function
const apiKey = process.env.GOOGLE_AI_API_KEY;
```

### Variable status indicators

Each variable shows its current status:

> [tab] Provided by Bloom
>
> This variable is auto-provisioned by Bloom. The API key is managed automatically and rotated for security.
>
> **Example:** `Google_AI` when auto-provisioning is enabled
>
> > [!TIP]
> >
> > No manual configuration needed
>
> > [!TIP]
> >
> > Counts against your plan credits

> [tab] In use
>
> This variable is actively being used by your app's backend functions.
>
> > [!TIP]
> >
> > Your code is successfully accessing this variable
>
> > [!TIP]
> >
> > The service connection is working

> [tab] Not in use
>
> If a variable shows no status badge, it's defined but not currently being used in any backend functions.
>
> This might mean:
>
> * You added it but haven't implemented the feature yet
> * The variable name doesn't match what your code is looking for
> * The code using it isn't being called

### Actions for variables

> [accordion] Edit variable
>
> Click the **edit icon** (pencil) to change a variable's value.
>
> > [!WARNING]
> >
> > Changing a variable value will affect your live app immediately. Make sure you're updating the correct variable!
>
> **Common reasons to edit:**
>
> * Rotating API keys for security
> * Updating configuration values
> * Fixing incorrect credentials

> [accordion] Delete variable
>
> Click the **delete icon** (trash can) to remove a variable.
>
> > [!WARNING]
> >
> > Deleting a variable that's in use will cause errors in your app. Check that no functions depend on it before deleting.
>
> **Check logs after deleting** to ensure no functions are trying to access the removed variable.

> [accordion] Refresh variables
>
> Click **Refresh** to reload the list of variables and their current status.
>
> Useful after:
>
> * Adding variables in the Convex dashboard directly
> * Making changes in another browser tab
> * Troubleshooting variable visibility issues

## Common use cases

> [accordion] Adding a custom AI API key
>
> If you want to use your own Google AI, OpenAI, or Anthropic API key:
>
> **1. Disable auto-provisioning**
>
> Toggle off "Automatically provision API keys" if it's enabled.
>
> **2. Get your API key**
>
> * For Google AI: [Google AI Studio](https://aistudio.google.com/)
> * For OpenAI: [OpenAI Platform](https://platform.openai.com/)
> * For Anthropic: [Anthropic Console](https://console.anthropic.com/)
>
> **3. Add as environment variable**
>
> Click "Add Variable" and enter:
>
> * Name: `GOOGLE_AI_API_KEY` (or appropriate name)
> * Value: Your API key from the provider
>
> **4. Update your code**
>
> Make sure your backend functions use `process.env.GOOGLE_AI_API_KEY`
>
> **5. Test the connection**
>
> Use your app's AI features and check [Logs](https://docs.bloom.diy/logs.md) for any errors

> [accordion] Connecting a payment processor
>
> To add Stripe, PayPal, or another payment service:
>
> **1. Create an account**
>
> Sign up with your chosen payment processor (e.g., [Stripe](https://stripe.com))
>
> **2. Get API credentials**
>
> Find your API keys in the service's dashboard:
>
> * Stripe: Dashboard → Developers → API keys
> * Look for "Secret key" or "API key"
>
> **3. Add to environment variables**
>
> * Name: `STRIPE_SECRET_KEY` (or provider-specific name)
>
> * Value: Your secret API key
>
> > [!WARNING]
> >
> > Never use "publishable" keys in environment variables—only "secret" keys belong in the backend.
>
> **4. Implement payment logic**
>
> Use Bloom's agent to help generate payment processing code, or follow the provider's documentation

> [accordion] Setting up analytics
>
> To track user behavior with Mixpanel, Segment, or Google Analytics:
>
> **1. Create analytics account**
>
> Sign up with your chosen analytics platform
>
> **2. Get tracking credentials**
>
> Each platform provides:
>
> * API key or Write key
> * Project ID or tracking ID
>
> **3. Add as environment variables**
>
> Example for Mixpanel:
>
> * `MIXPANEL_TOKEN`: Your project token
> * `MIXPANEL_SECRET`: Your API secret (if using server-side tracking)
>
> **4. Initialize tracking**
>
> Add tracking calls to your backend functions or frontend code as needed

> [accordion] Switching from Bloom-managed to custom keys
>
> If you started with auto-provisioned keys but want to use your own:
>
> **1. Get your own API key**
>
> Create an account with the service provider and generate an API key
>
> **2. Add the new variable**
>
> Create an environment variable with your custom key (don't delete the Bloom one yet)
>
> **3. Update your code**
>
> Change your functions to use the new variable name
>
> **4. Test thoroughly**
>
> Verify everything works with your custom key before proceeding
>
> **5. Disable auto-provisioning**
>
> Once confirmed working, toggle off auto-provisioning to stop using Bloom credits
>
> **6. Remove old variable (optional)**
>
> Delete the Bloom-provided variable if no longer needed

## Security best practices

> [card] Never commit keys to code
>
> Always use environment variables—never hard-code API keys directly in your app's source code.

> [card] Rotate keys regularly
>
> Change API keys periodically for security, especially if team members leave or keys are potentially exposed.

> [card] Use separate keys per environment
>
> If exporting code for production, use different API keys for development vs. production deployments.

> [card] Monitor usage
>
> Check provider dashboards regularly for unexpected API usage that might indicate a security issue.

> [!WARNING]
>
> **If you suspect an API key is compromised:**
>
> 1. Immediately delete the variable in Bloom
> 2. Revoke the key in the provider's dashboard
> 3. Generate a new key and add it as a fresh variable
> 4. Check [Logs](https://docs.bloom.diy/logs.md) for suspicious activity

## Troubleshooting

> [accordion] API calls failing with 'key not valid'
>
> **Possible causes:**
>
> * The API key is incorrect or expired
> * The key doesn't have required permissions
> * Auto-provisioning is disabled but no custom key is set
> * Variable name doesn't match what your code expects
>
> **Solutions:**
>
> 1. Verify the key is correct in the provider's dashboard
> 2. Check the variable name matches your code exactly
> 3. Enable auto-provisioning if you want Bloom-managed keys
> 4. View [Logs](https://docs.bloom.diy/logs.md) for the specific error message

> [accordion] Variable not showing as 'In use'
>
> If you added a variable but it doesn't show the "In use" badge:
>
> * Your code might not be calling the function that uses it yet
> * The variable name in your code might not match exactly
> * You might be checking `process.env` incorrectly in your function
>
> Check [Backend Dashboard Functions](https://docs.bloom.diy/backend-dashboard.md) to verify the function is being called.

> [accordion] Credits depleted
>
> If auto-provisioning is disabled due to insufficient credits:
>
> **Option 1: Upgrade plan**
>
> * Get more included credits through a paid billing cycle
> * Keep using Bloom-managed keys
> * Simplest for ongoing projects
>
> **Option 2: Use custom keys**
>
> * Disable auto-provisioning
> * Add your own API keys
> * Direct billing from service providers

> [accordion] Can't find my variable
>
> * Click **Refresh** to reload the variable list
> * Check you're in the correct app's settings
> * Verify the variable was saved (you should see a confirmation)
> * Check if it was accidentally deleted

## Learn more

> [card] [View Logs](https://docs.bloom.diy/logs.md)
>
> Debug API connection errors and see request details

> [card] [Backend Dashboard](https://docs.bloom.diy/backend-dashboard.md)
>
> Monitor function calls that use API connections

> [card] [Plans & Pricing](https://docs.bloom.diy/pricing-and-credits.md)
>
> Understand credit usage for auto-provisioned keys

> [card] [Convex Environment Variables](https://docs.convex.dev/production/environment-variables)
>
> Learn more about how Convex handles environment variables


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.