Overview
To use OpenAI models (GPT-4, GPT-3.5, etc.) with AgentClaw, you need an API key from OpenAI. This guide shows you how to create one.
Step 1: Create an OpenAI Account
- Go to platform.openai.com/signup
- Sign up with your email or continue with Google/Microsoft
- Verify your email address
- Complete the registration process
Step 2: Add Payment Method
OpenAI requires a payment method to use the API:
- Log in to the OpenAI Platform
- Click your profile icon in the top right
- Select "Billing"
- Click "Add payment method"
- Enter your credit card information
Note: You won't be charged until you use the API. OpenAI uses pay-as-you-go pricing.
Step 3: Create an API Key
- Navigate to platform.openai.com/api-keys
- Click "Create new secret key"
- Give your key a name (e.g., "AgentClaw Bot")
- Set permissions (choose "All" for full access)
- Click "Create secret key"
- Important: Copy the key immediately - you won't be able to see it again!
Step 4: Add Key to AgentClaw
- Go to your AgentClaw instance configuration
- Add a new environment variable:
- Name:
OPENAI_API_KEY - Value: Paste your API key (starts with
sk-)
- Name:
- Save the configuration
- Restart your instance
See Adding API Keys Securely for detailed instructions.
Setting Usage Limits
To prevent unexpected costs, set up usage limits in OpenAI:
- Go to Billing → Usage limits
- Set a monthly budget (e.g., $20, $50, $100)
- Enable email notifications at 75% and 100%
- OpenAI will stop serving requests when limit is reached
Pricing Overview
OpenAI charges per token (roughly per word). As of 2026:
- GPT-4.1: ~$0.01 per 1K input tokens, ~$0.03 per 1K output tokens
- GPT-4 Turbo: ~$0.01 per 1K tokens
- GPT-3.5 Turbo: ~$0.0005 per 1K tokens
Check openai.com/pricing for current pricing.
Monitoring Usage
Track your API usage in the OpenAI Platform:
- Go to Usage in the OpenAI Platform
- View daily usage graphs
- See breakdown by model
- Download usage reports
Best Practices
- Use different keys for different projects: Easier to track usage and revoke if needed
- Set usage limits: Prevent unexpected bills
- Never commit keys to version control: Keep them secure
- Rotate keys regularly: Update keys every few months for security
- Monitor usage: Check OpenAI dashboard weekly
Revoking Keys
If a key is compromised:
- Go to platform.openai.com/api-keys
- Find the compromised key
- Click "Revoke"
- Create a new key
- Update your AgentClaw configuration with the new key
Troubleshooting
Invalid API key error
- Ensure you copied the full key (starts with
sk-) - Check for extra spaces or characters
- Verify the key hasn't been revoked
Quota exceeded error
- You've hit your monthly usage limit
- Increase your limit in OpenAI Billing settings
- Or wait until next month for limit to reset
Rate limit error
- Too many requests in a short time
- Implement retry logic (OpenClaw does this automatically)
- Upgrade to higher tier for increased rate limits
Free Credits
New OpenAI accounts receive $5 in free credits valid for 3 months. This is enough to test your bot with several hundred messages.
Next Steps
- Learn about choosing the right AI model
- Get Anthropic API keys for Claude models
- Explore OpenRouter for multi-model access
- Read the environment variables guide