API Setup
Learn how to configure your OpenAI API key and customize Helse's API settings for optimal performance.
In This Guide
- API Configuration
- Configuration Options
- Model Selection
- Usage Management
- Environment-Specific Settings
- Troubleshooting
- Best Practices
- Next Steps
API Configuration
Helse requires an OpenAI API key to power its AI features. This guide will help you set up and configure your API access.
Getting Your API Key
1
Create OpenAI Account
- Visit OpenAI's website
- Click "Sign Up" or "Log In"
- Complete the registration process
2
Generate API Key
- Navigate to the API section
- Click "Create New API Key"
- Name your key (e.g., "Helse Research")
- Copy the generated key
Security:
Store your API key securely. Never commit it to version control or share it publicly.
Configuration Options
Basic Setup
Configure your API key using the CLI:
helse config set OPENAI_API_KEY=your_api_key_here
Or create a .env
file in your project root:
OPENAI_API_KEY=your_api_key_here
MODEL=gpt-4
MAX_TOKENS=2000
Advanced Configuration
Create a helse.config.js
file for detailed settings:
module.exports = {
api: {
key: process.env.OPENAI_API_KEY,
model: 'gpt-4',
maxTokens: 2000,
temperature: 0.7
},
features: {
writing: {
style: 'academic',
tone: 'formal'
},
references: {
defaultStyle: 'apa',
autoFormat: true
}
}
};
Model Selection
Helse supports various OpenAI models:
Model | Use Case | Token Limit |
---|---|---|
GPT-4 | Complex research, analysis | 8,192 |
GPT-3.5-Turbo | General writing, drafts | 4,096 |
GPT-3.5 | Quick summaries | 2,048 |
Setting the Default Model
helse config set MODEL=gpt-4
Usage Management
Monitor and manage your API usage:
1
View Usage
helse usage stats
2
Set Limits
helse config set MAX_DAILY_TOKENS=100000
3
Export Reports
helse usage export --format csv --month current
Environment-Specific Settings
Configure different settings for development and production:
// helse.config.js
module.exports = {
development: {
api: {
model: 'gpt-3.5-turbo',
maxTokens: 1000
}
},
production: {
api: {
model: 'gpt-4',
maxTokens: 2000
}
}
};
Troubleshooting
Common issues and solutions:
API Key Invalid:
If you receive an "Invalid API Key" error:
- Verify the key in your configuration
- Ensure the key has not expired
- Check for proper environment variable loading
Rate Limits:
If you hit rate limits:
- Implement request throttling
- Consider upgrading your OpenAI plan
- Optimize token usage in your requests
Best Practices
-
Security
- Use environment variables
- Rotate API keys periodically
- Implement proper error handling
-
Performance
- Cache responses when possible
- Use appropriate models for tasks
- Monitor token usage
-
Cost Management
- Set usage alerts
- Implement rate limiting
- Use cheaper models for drafts