Skip to main content

Get Your API Key

  1. Visit Legnext Dashboard
  2. Log in to your account
  3. Navigate to API Keys section
  4. Create a new API key
  5. Copy and save it securely

Using Your API Key

Method 1: Direct Initialization

const { Configuration, ImageApi } = require('@legnext-api/js-sdk');

const config = new Configuration({
    basePath: 'https://api.legnext.ai'
});

const imageApi = new ImageApi(config);

const apiKey = 'your-api-key-here';
// Use apiKey as first parameter in method calls
TypeScript:
import { Configuration, ImageApi } from '@legnext-api/js-sdk';

const config = new Configuration({
    basePath: 'https://api.legnext.ai'
});

const imageApi = new ImageApi(config);

const apiKey: string = 'your-api-key-here';
// Use apiKey as first parameter in method calls
Set the environment variable:
# macOS/Linux
export LEGNEXT_API_KEY="your-api-key-here"

# Windows CMD
set LEGNEXT_API_KEY=your-api-key-here

# Windows PowerShell
$env:LEGNEXT_API_KEY="your-api-key-here"
Then in your code:
const apiKey = process.env.LEGNEXT_API_KEY;

const imageApi = new ImageApi(apiClient);
// Use apiKey in method calls

Method 3: .env File (Node.js)

Create a .env file:
LEGNEXT_API_KEY=your-api-key-here
LEGNEXT_BASE_URL=https://api.legnext.ai
Install and use dotenv:
npm install dotenv
require('dotenv').config();

const { Configuration, ImageApi } = require('@legnext-api/js-sdk');

const config = new Configuration({
    basePath: process.env.LEGNEXT_BASE_URL || 'https://api.legnext.ai'
});

const imageApi = new ImageApi(config);
const apiKey = process.env.LEGNEXT_API_KEY;

Method 4: ES Modules

import 'dotenv/config';
import { Configuration, ImageApi } from '@legnext-api/js-sdk';

const config = new Configuration({
    basePath: process.env.LEGNEXT_BASE_URL || 'https://api.legnext.ai'
});

const imageApi = new ImageApi(config);
const apiKey = process.env.LEGNEXT_API_KEY;

Security Best Practices

⚠️ Never hardcode API keys in your code Always use environment variables Add .env to .gitignore Never expose API keys in client-side JavaScript Rotate keys regularly and revoke compromised ones

Next Steps