API Setup

Learn how to configure your OpenAI API key and customize Helse's API settings for optimal performance.

In This Guide

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

  1. Visit OpenAI's website
  2. Click "Sign Up" or "Log In"
  3. Complete the registration process
2

Generate API Key

  1. Navigate to the API section
  2. Click "Create New API Key"
  3. Name your key (e.g., "Helse Research")
  4. 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:

ModelUse CaseToken Limit
GPT-4Complex research, analysis8,192
GPT-3.5-TurboGeneral writing, drafts4,096
GPT-3.5Quick summaries2,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:

  1. Verify the key in your configuration
  2. Ensure the key has not expired
  3. Check for proper environment variable loading

Rate Limits:

If you hit rate limits:

  1. Implement request throttling
  2. Consider upgrading your OpenAI plan
  3. Optimize token usage in your requests

Best Practices

  1. Security

    • Use environment variables
    • Rotate API keys periodically
    • Implement proper error handling
  2. Performance

    • Cache responses when possible
    • Use appropriate models for tasks
    • Monitor token usage
  3. Cost Management

    • Set usage alerts
    • Implement rate limiting
    • Use cheaper models for drafts

Next Steps