Installation

Install and configure @constela/ai

Package Installation

bash
npm install @constela/ai

Or with other package managers:

bash
# pnpm
pnpm add @constela/ai

# yarn
yarn add @constela/ai

Environment Setup

Create a .env file in your project root and add your API key:

text
# For Anthropic (Claude)
ANTHROPIC_API_KEY=sk-ant-...

# For OpenAI
OPENAI_API_KEY=sk-...

Make sure .env is in your .gitignore to avoid committing secrets.

Verification

Test your installation by creating a DSL file with AI data source:

json
{
  "version": "1.0",
  "data": {
    "testComponent": {
      "type": "ai",
      "provider": "anthropic",
      "prompt": "A simple button component",
      "output": "component"
    }
  },
  "view": {
    "kind": "component",
    "name": "testComponent",
    "props": {}
  }
}

Then build your project:

bash
constela build

If the build succeeds without errors, the installation is complete.

CLI Integration

The constela suggest command is automatically available when you have @constela/cli installed:

bash
# Ensure @constela/cli is installed
npm install -D @constela/cli

# Use the suggest command
constela suggest app.json --aspect accessibility