Quick Start

Get up and running with the Fig1 SDK in under 5 minutes.

Prerequisites

Step 1: Make Your First Request

Let's send a message to the AI agent:

curl -X POST https://app.fig1.ai/api/sdk/agent/chat \
  -H "Content-Type: application/json" \
  -H "X-Fig1-API-Key: YOUR_API_KEY" \
  -d '{"message": "Hello, what can you help me with?"}'

You'll receive a response like:

{
  "success": true,
  "data": {
    "message": "Hello! I can help you with information about our products...",
    "sessionId": "sess_abc123",
    "metadata": {
      "tokensUsed": 156
    }
  }
}

Step 2: Continue the Conversation

Use the sessionId to maintain context across messages:

curl -X POST https://app.fig1.ai/api/sdk/agent/chat \
  -H "Content-Type: application/json" \
  -H "X-Fig1-API-Key: YOUR_API_KEY" \
  -d '{
    "message": "Tell me more about the first option",
    "sessionId": "sess_abc123"
  }'

Step 3: Add to Your Application

JavaScript/TypeScript

async function chat(message: string, sessionId?: string) {
  const response = await fetch('https://app.fig1.ai/api/sdk/agent/chat', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'X-Fig1-API-Key': process.env.FIG1_API_KEY!
    },
    body: JSON.stringify({ message, sessionId })
  });

  const data = await response.json();

  if (!data.success) {
    throw new Error(data.error);
  }

  return data.data;
}

// Usage
const response = await chat('What products do you recommend?');
console.log(response.message);

// Continue conversation
const followUp = await chat('Tell me more', response.sessionId);

Python

import requests
import os

def chat(message: str, session_id: str = None):
    response = requests.post(
        'https://app.fig1.ai/api/sdk/agent/chat',
        headers={
            'Content-Type': 'application/json',
            'X-Fig1-API-Key': os.environ['FIG1_API_KEY']
        },
        json={
            'message': message,
            'sessionId': session_id
        }
    )

    data = response.json()

    if not data['success']:
        raise Exception(data['error'])

    return data['data']

# Usage
response = chat('What products do you recommend?')
print(response['message'])

# Continue conversation
follow_up = chat('Tell me more', response['sessionId'])

Step 4: Use a Persona (Optional)

Personas customize how the AI responds. If you've created personas in the dashboard:

const response = await fetch('https://app.fig1.ai/api/sdk/agent/chat', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-Fig1-API-Key': process.env.FIG1_API_KEY!
  },
  body: JSON.stringify({
    message: 'Help me choose a product',
    personaId: 'persona_sales_assistant'
  })
});

Step 5: Pass User Preferences (Optional)

Help the AI give personalized responses:

const response = await fetch('https://app.fig1.ai/api/sdk/agent/chat', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-Fig1-API-Key': process.env.FIG1_API_KEY!
  },
  body: JSON.stringify({
    message: 'What do you recommend?',
    preferences: {
      products: {
        likes: ['organic', 'sustainable'],
        priceRange: { min: 20, max: 100 }
      }
    }
  })
});

What's Next?