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

Method 2: Direct Initialization

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

Method 3: Using vlucas/phpdotenv

Use the vlucas/phpdotenv package to load from .env files:
.env file:

Method 4: Configuration File

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

Method 5: Framework Integration (Laravel)

For Laravel applications, use environment variables: .env:
config/legnext.php:
Usage in Laravel:

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
  7. Protect configuration files

Testing Authentication

Verify your API key is working:

Debugging

Enable debugging to see HTTP requests and responses:

Error Handling


Next Steps