Skip to main content

Getting Your API Key

  1. Visit Legnext.ai Dashboard
  2. Navigate to API Keys section
  3. Generate a new API key
  4. Copy and store securely

Authentication Methods

Set your API key as an environment variable:
Then use it in your Ruby code:

Method 2: Direct Initialization

Hardcode the API key directly (not recommended for production):

Method 3: Using dotenv Gem

Use the dotenv gem to load from .env files:
.env file:

Method 4: YAML Configuration File

Load API key from a YAML configuration file:
config.yml:

Method 5: Rails Credentials (for Rails Applications)

For Rails 5.2+, use encrypted credentials:
Add to credentials:
In your Rails app:

Complete Configuration Example


Security Best Practices

  1. Never commit API keys to version control
  2. Use environment variables in production
  3. Rotate keys regularly
    • Generate new keys periodically
    • Revoke old keys after rotation
  4. Use different keys for development and production
  5. Restrict API key permissions
    • Use the minimum required permissions
    • Monitor usage through the dashboard
  6. Enable SSL verification

Testing Authentication

Verify your API key is working:

Debugging

Enable debugging to see HTTP requests and responses:

Next Steps