Skip to main content
Get up and running with Layer AI in just a few minutes. This guide will walk you through creating your first gate and making your first AI request.

1. Sign Up

Create your Layer AI account at uselayer.ai/signup.

2. Get Your API Key

  1. Go to your Dashboard
  2. Navigate to API Keys
  3. Click Create New Key
  4. Copy your API key and store it securely
Keep your API key secret! Never commit it to version control or share it publicly.

3. Create Your First Gate

Gates are Layer AI’s core abstraction for routing and managing AI requests.
  1. In your Dashboard, go to Gates
  2. Click Create Gate
  3. Configure your gate:
    • Name: my-first-gate
    • Primary Model: gpt-4o-mini
    • Fallback Models: claude-sonnet-4, gemini-2.0-flash-exp
    • System Prompt: “You are a helpful assistant”
  4. Click Create
  5. Copy your Gate ID (you’ll need this for requests)

4. Install the SDK

npm install @layer-ai/sdk

5. Make Your First Request

import { Layer } from '@layer-ai/sdk';

const layer = new Layer({
  apiKey: process.env.LAYER_API_KEY
});

const response = await layer.chat({
  gateId: 'your-gate-id',  // Replace with your gate ID
  data: {
    messages: [
      { role: 'user', content: 'Explain quantum computing in simple terms' }
    ]
  }
});

console.log(response.content);
console.log(`Cost: $${response.cost.toFixed(6)}`);
console.log(`Model used: ${response.model}`);

6. Set Environment Variables

Create a .env file in your project root:
.env
LAYER_API_KEY=your_api_key_here
GATE_ID=your_gate_id_here
Then load it in your code:
import 'dotenv/config';

const layer = new Layer({
  apiKey: process.env.LAYER_API_KEY
});

What’s Next?

Common Use Cases

Chatbot with Conversation History

const messages = [
  { role: 'system', content: 'You are a helpful coding assistant' },
  { role: 'user', content: 'How do I reverse a string in Python?' },
  { role: 'assistant', content: 'You can reverse a string using slicing: `text[::-1]`' },
  { role: 'user', content: 'Can you show me a complete example?' }
];

const response = await layer.chat({
  gateId: process.env.GATE_ID!,
  data: { messages }
});

Image Generation

const response = await layer.image({
  gateId: process.env.IMAGE_GATE_ID!,
  data: {
    prompt: 'A serene mountain landscape at sunset',
    size: '1024x1024',
    quality: 'hd'
  }
});

console.log(response.imageUrl);

With Custom Parameters

const response = await layer.chat({
  gateId: process.env.GATE_ID!,
  data: {
    messages: [
      { role: 'user', content: 'Write a creative story about robots' }
    ],
    temperature: 0.9,  // Higher creativity
    maxTokens: 1000
  }
});

Need Help?

Join our Discord Community

Get help, share feedback, and connect with other Layer AI users