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 Go code:

Method 2: Direct Initialization

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

Method 3: Configuration File

Load API key from a configuration file:
config.json:

Method 4: Using godotenv

Use the godotenv package to load from .env files:
.env file:

Security Best Practices

  1. Never commit API keys to version control
    • Add .env and config.json to .gitignore
    • Use environment variables in production
  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

Testing Authentication

Verify your API key is working:

Next Steps