How to Manage API Keys for Your AI Agent
API keys are the bridge between your AI agent and the model providers that power its intelligence. Managing them properly is essential for security, cost control, and reliable agent operation. A poorly managed key can lead to unauthorized charges, agent downtime, or security vulnerabilities.
This guide covers everything about API key management for your EZClaws agents: obtaining keys from providers, configuring them on EZClaws, setting spending limits, rotating keys, and handling compromised keys. Whether this is your first API key or you are managing keys for multiple agents, this guide has you covered.
Prerequisites
To follow this guide, you need:
- An EZClaws account — Sign up at ezclaws.com.
- An account with a model provider — OpenAI, Anthropic, Google (Gemini), or Replicate. If you do not have one, this guide will walk you through creating one.
- A payment method on the provider account — Most providers require a payment method before you can use their API.
Step 1: Choose a Model Provider
If you have not chosen a provider yet, here is a quick comparison:
Provider | Best Model | Best For | Starting Cost
------------|---------------|---------------------|------------------
OpenAI | GPT-4o | General purpose | ~$0.15/1M tokens (mini)
Anthropic | Claude Sonnet | Code, writing | ~$0.25/1M tokens (haiku)
Google | Gemini Pro | Cost-effective | ~$0.075/1M tokens (flash)
Replicate | Various | Open-source models | Varies by model
For beginners, we recommend OpenAI — it has the largest community, extensive documentation, and reliable API. For a detailed comparison, see our model provider configuration guide.
Step 2: Create a Provider Account and Get Your API Key
OpenAI
- Create an account at platform.openai.com.
- Add a payment method — Go to Settings > Billing > Payment methods. Add a credit card or debit card.
- Add credits — New accounts need a minimum balance. Start with $5-10 for testing.
- Navigate to API keys — Click on "API keys" in the left sidebar.
- Create a new key — Click "Create new secret key."
- Name your key — Give it a descriptive name like "EZClaws Support Bot" or "My AI Agent."
- Copy the key immediately — The full key is only shown once. Copy it and store it securely.
Your OpenAI key looks like:
sk-proj-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Important:
- The key starts with "sk-proj-" or "sk-"
- It is a long alphanumeric string
- You CANNOT view it again after creation
- If you lose it, you must create a new one
Anthropic
- Create an account at console.anthropic.com.
- Add billing information — Navigate to Settings > Billing.
- Navigate to API Keys — Go to Settings > API Keys.
- Create a key — Click "Create Key."
- Name and copy — Name it descriptively and copy immediately.
Your Anthropic key looks like:
sk-ant-apixx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Google (Gemini)
- Sign in at aistudio.google.com with your Google account.
- Navigate to API keys — Look for the "Get API key" option.
- Create a key — Click "Create API key."
- Copy the key — Store it securely.
Your Google API key looks like:
AIzaSyXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
For production use with higher quotas, create the key through Google Cloud Console instead.
Replicate
- Create an account at replicate.com.
- Navigate to API tokens — Go to Account Settings > API Tokens.
- Copy your token — Your API token is displayed on the page.
Your Replicate token looks like:
r8_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Step 3: Configure the API Key on EZClaws
Once you have your key, add it to your EZClaws agent.
For a New Agent
During the agent creation process:
- Go to your dashboard at
/app. - Click Deploy New Agent.
- Select your Model Provider from the dropdown.
- Paste your API Key in the designated field.
- Complete the remaining fields (name, region).
- Click Deploy Agent.
For an Existing Agent
To add or update an API key:
- Navigate to your agent's detail page at
/app/agents/[id]. - Open the configuration or settings panel.
- Find the Model Provider and API Key fields.
- Select the provider (if changing) and paste the new key.
- Save the changes.
The agent will use the new key on its next request. No restart is needed.
Verification
After configuring the key, verify it works:
- Check that your agent's status is "Running" on the dashboard.
- Send a test message through your connected channel (Telegram, etc.).
- If the agent responds, the key is working correctly.
- If the agent shows an error, double-check the key and provider selection.
Step 4: Secure Your API Key
API key security is not optional. A compromised key can result in unauthorized charges and potential data exposure.
Security Best Practices
DO:
- Store keys in a password manager (1Password, Bitwarden, etc.)
- Use unique keys for each agent
- Set spending limits on every key
- Rotate keys regularly (every 90 days)
- Revoke keys immediately if compromised
- Monitor usage on the provider's dashboard
DO NOT:
- Share keys via email, Slack, or chat
- Store keys in plain text files
- Commit keys to Git repositories
- Include keys in screenshots
- Reuse keys across multiple applications
- Share keys with colleagues (they should use their own)
After Entry on EZClaws
Once you enter your API key on EZClaws:
- The key is encrypted at rest.
- The dashboard will not display the full key again (it may show the last few characters for identification).
- The key is passed to your agent's container as an encrypted environment variable.
- The key is never included in logs or error messages.
Step 5: Set Spending Limits
Spending limits are your safety net against unexpected charges. Set them on your provider account.
OpenAI Spending Limits
- Go to platform.openai.com/settings/limits.
- Set a monthly budget limit — This is the maximum you can spend in a calendar month.
- Set an email notification threshold — Get alerted before you hit the limit.
Recommended limits for EZClaws agents:
Testing/Development: $10/month
Personal agent (light use): $25/month
Personal agent (regular use): $50/month
Team agent (moderate): $100/month
Production (high traffic): $200-500/month
Anthropic Spending Limits
- Go to console.anthropic.com/settings/billing.
- Set your usage limit for the billing period.
- Configure notification thresholds.
Google Spending Limits
- Go to Google Cloud Console > Billing > Budgets & Alerts.
- Create a budget for the Gemini API.
- Set alert thresholds at 50%, 80%, and 100% of budget.
Why Limits Matter
Without spending limits:
Scenario: API key compromised
- No limit: Attacker runs up $500+ in charges before you notice
- With $50 limit: Maximum exposure is $50, and you get notified
Scenario: Agent misconfiguration causes a loop
- No limit: Thousands of API calls in minutes, hundreds of dollars
- With limit: Spending stops at your defined maximum
Step 6: Rotate Keys Regularly
Key rotation is a fundamental security practice. Even if nothing has gone wrong, regular rotation limits the window of exposure for any key.
Rotation Process
- Generate a new key on your provider's dashboard.
- Update the key in your EZClaws agent configuration.
- Test the agent — Send a message to verify the new key works.
- Revoke the old key on the provider's dashboard.
- Update your records — Note the rotation date in your password manager.
# Rotation schedule:
Routine rotation: Every 90 days
After team member leaves: Immediately
After suspected compromise: Immediately
After a security audit: If recommended
# Set a calendar reminder:
"Rotate API keys for EZClaws agents"
Repeat: Every 3 months
Safe Rotation Steps (Zero Downtime)
To rotate without any downtime:
- Create the new key (the old key still works).
- Update EZClaws with the new key.
- Wait 5 minutes for the change to propagate.
- Test to confirm the new key works.
- Only then revoke the old key.
This ensures there is no moment when neither key is active.
Step 7: Handle Compromised Keys
If you suspect your API key has been compromised (unauthorized usage, key shared accidentally, etc.), act immediately:
Emergency Response Steps
1. REVOKE the key NOW (do not wait)
- Go to your provider's dashboard
- Find the compromised key
- Click "Revoke" or "Delete"
- The key stops working instantly
2. GENERATE a new key
- Create a new key on the provider
- Give it a new name (e.g., "Agent-v2-2026-02")
3. UPDATE EZClaws
- Go to your agent's configuration
- Enter the new key
- Save changes
4. CHECK for damage
- Review your provider's usage dashboard
- Look for unusual API calls (spikes in usage, unknown models)
- Check the billing for unexpected charges
5. REPORT if necessary
- If significant unauthorized charges occurred,
contact the provider's support team
- Most providers will investigate and potentially
reverse fraudulent charges
6. PREVENT recurrence
- Identify how the key was compromised
- Set or lower spending limits
- Review your security practices
Common Compromise Scenarios
Scenario: Key committed to a public GitHub repo
Response: Revoke immediately. GitHub's secret scanning may alert you,
but do not wait for the alert.
Scenario: Key shared in a Slack message
Response: Revoke and rotate. Anyone with access to that Slack channel
now has the key.
Scenario: Unusual charges on provider dashboard
Response: Revoke all potentially affected keys. Investigate which
key was used.
Scenario: Former team member had access
Response: Rotate all keys they had access to.
Step 8: Manage Multiple Keys
As you scale to multiple agents, key management becomes more important.
One Key Per Agent
The recommended approach:
Agent: Support Bot → API Key: sk-proj-support-xxxx (OpenAI)
Agent: Research Bot → API Key: sk-ant-research-xxxx (Anthropic)
Agent: Team Helper → API Key: sk-proj-helper-xxxx (OpenAI)
Benefits:
- Revoke one key without affecting other agents.
- Track per-agent usage on the provider's dashboard.
- Set different spending limits per agent.
Key Inventory
Maintain an inventory of all your keys:
Key Inventory (store securely, e.g., password manager):
Key Name | Provider | Agent | Created | Next Rotation
------------------|-----------|----------------|------------|---------------
support-bot-v3 | OpenAI | Support Bot | 2026-01-15 | 2026-04-15
research-bot-v2 | Anthropic | Research Bot | 2026-02-01 | 2026-05-01
team-helper-v1 | OpenAI | Team Helper | 2026-02-10 | 2026-05-10
Provider Account Organization
For teams with many agents:
OpenAI:
Project: EZClaws Production
Key: support-bot-prod
Key: team-helper-prod
Project: EZClaws Development
Key: dev-testing
Anthropic:
Workspace: EZClaws
Key: research-bot-prod
Key: writing-assistant-prod
Organize keys into projects or workspaces on the provider side for cleaner management.
Troubleshooting
"Invalid API key" error when deploying
- Re-copy the key — Go back to your provider dashboard and copy the key fresh.
- Check for whitespace — Ensure no leading or trailing spaces when pasting.
- Verify the provider — Make sure you selected the correct provider for the key (e.g., OpenAI key with OpenAI selected).
- Check key status — The key may have been revoked or the account may be suspended.
Agent was working but suddenly stopped
- Check if the key was revoked — Log in to your provider dashboard and verify the key is active.
- Check spending limits — You may have hit your provider's spending limit.
- Check provider status — The provider may be experiencing an outage.
- Check credit balance — Verify your EZClaws credits at
/app/billing.
Cannot find my API key
- You cannot view old keys — Most providers only show the key once at creation.
- Create a new key — Generate a fresh key on your provider's dashboard.
- Revoke the old one — If you cannot identify which key is which, revoke all unused keys.
- Use a password manager — Store new keys in a password manager to avoid this in the future.
Provider charges seem too high
- Check EZClaws usage — Compare with your billing at
/app/billing. - Check for other usage — The same key might be used by other applications.
- Review per-request costs — See our usage monitoring guide.
- Set tighter limits — Lower your spending limit to match actual needs.
- See cost optimization — Our cost reduction guide has detailed strategies.
Summary
API key management is a foundational skill for running AI agents. The process is simple: obtain a key from your model provider, configure it on EZClaws, set spending limits, and rotate regularly. Good habits here prevent security incidents, control costs, and ensure your agents run reliably.
The most important practices are: use unique keys per agent, always set spending limits, store keys in a password manager, and rotate every 90 days. If a key is ever compromised, revoke it immediately — you can always create a new one.
For more on configuring model providers, see our provider configuration guide. For cost management, explore our usage monitoring guide and cost reduction guide. Visit our blog for the latest best practices and tips.
Frequently Asked Questions
An API key is a unique code that authenticates your AI agent with a model provider like OpenAI or Anthropic. It is like a password that tells the provider 'this agent is authorized to use my AI models.' Without an API key, your agent cannot generate responses.
No. EZClaws provides the hosting platform for your AI agent. You bring your own API key from your chosen model provider (OpenAI, Anthropic, Google, Replicate). This gives you full control over your model provider account, spending limits, and model selection.
Yes. EZClaws encrypts your API key at rest and never exposes it in the dashboard after initial entry, in logs, or in API responses. The key is securely passed to your agent's isolated container as an encrypted environment variable.
If your API key is compromised, someone could use it to make API calls at your expense. Immediately revoke the key on your provider's dashboard and generate a new one. Having spending limits set on your provider account limits the potential damage.
Technically yes, but we recommend using separate keys for each agent. Separate keys let you track per-agent usage on the provider's dashboard, set different spending limits, and revoke a single key without affecting other agents.
Explore More
From the Blog
Everything you need to know about managing API keys for your AI agent. Covers key generation for OpenAI, Anthropic, and Google, plus security best practices, cost controls, and rotation.
11 min read25 AI Agent Automation Ideas You Can Set Up TodayDiscover 25 practical AI agent automation ideas for business, productivity, community, and personal use. Each idea includes what the agent does, who it helps, and how to set it up on EZClaws.
16 min readAI Agent for Customer Support: A Real-World Case StudySee how a growing e-commerce company deployed an AI agent for customer support using OpenClaw and EZClaws, reducing response times by 85% and handling 70% of tickets autonomously.
12 min readReady to Deploy Your AI Agent?
Our provisioning engine spins up your private OpenClaw instance — dedicated VM, HTTPS endpoint, and full autonomy in under a minute.
