> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sundaypyjamas.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Quick Start Guide

> Get up and running with the SundayPyjamas AI Suite API in just a few minutes

## Get Your API Key

Start by generating your API key from your workspace settings.

<Steps>
  <Step title="Access Workspace Settings">
    1. Log into your SundayPyjamas workspace
    2. Navigate to **Settings** → **API** tab
    3. Click **"Generate API Key"**
    4. Give your key a descriptive name (optional)
  </Step>

  <Step title="Save Your Key Securely">
    ```
    spj_ai_a1b2c3d4e5f6789012345678901234567890abcdef123456789012345678901234
    ```

    <Warning>
      Copy and store this key immediately - it won't be shown again!
    </Warning>
  </Step>
</Steps>

## Make Your First Request

Choose your preferred method to make your first API call:

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    const response = await fetch('https://suite.sundaypyjamas.com/api/v1/chat', {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer spj_ai_your_api_key_here',
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        messages: [
          {
            role: 'user',
            content: 'Hello! Write me a professional email greeting.'
          }
        ]
      })
    });

    const reader = response.body.getReader();
    const decoder = new TextDecoder();
    let result = '';

    while (true) {
      const { done, value } = await reader.read();
      if (done) break;
      result += decoder.decode(value);
    }

    console.log(result);
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    import requests

    response = requests.post(
        'https://suite.sundaypyjamas.com/api/v1/chat',
        headers={
            'Authorization': 'Bearer spj_ai_your_api_key_here',
            'Content-Type': 'application/json',
        },
        json={
            'messages': [
                {
                    'role': 'user',
                    'content': 'Hello! Write me a professional email greeting.'
                }
            ]
        },
        stream=True
    )

    full_response = ''
    for chunk in response.iter_content(chunk_size=None, decode_unicode=True):
        if chunk:
            full_response += chunk

    print(full_response)
    ```
  </Tab>

  <Tab title="cURL">
    ```bash theme={null}
    curl -X POST https://suite.sundaypyjamas.com/api/v1/chat \
      -H "Authorization: Bearer spj_ai_your_api_key_here" \
      -H "Content-Type: application/json" \
      -d '{
        "messages": [
          {
            "role": "user",
            "content": "Hello! Write me a professional email greeting."
          }
        ]
      }'
    ```
  </Tab>
</Tabs>

## Understanding the Response

The API returns a streaming text response. You'll receive the AI's response in real-time:

```
Hello! Here's a professional email greeting:

Dear [Recipient's Name],

I hope this email finds you well. I wanted to reach out to...
```

## Common Use Cases

<CardGroup cols={2}>
  <Card title="Content Generation" icon="pen-nib" href="/examples/javascript#content-generation">
    Generate blog posts, emails, and marketing copy with custom prompts.
  </Card>

  <Card title="Chat Interface" icon="comments" href="/examples/javascript#chat-interface-component">
    Build conversational AI interfaces with streaming responses.
  </Card>

  <Card title="Email Writing" icon="envelope" href="/examples/python#content-generation-tools">
    Create professional emails for various purposes and audiences.
  </Card>

  <Card title="Code Assistance" icon="code" href="/examples/python#batch-processing">
    Get help with programming tasks and code generation.
  </Card>
</CardGroup>

## Best Practices

### Secure Your API Key

<CodeGroup>
  ```bash Environment Variables theme={null}
  # Use environment variables
  export SUNDAYPYJAMAS_API_KEY="spj_ai_your_key_here"
  ```

  ```javascript In Your Code theme={null}
  // In your code
  const apiKey = process.env.SUNDAYPYJAMAS_API_KEY;
  ```
</CodeGroup>

### Handle Errors Gracefully

```javascript theme={null}
try {
  const response = await fetch('/api/v1/chat', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${apiKey}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({ messages })
  });

  if (!response.ok) {
    const error = await response.json();
    throw new Error(error.error);
  }

  // Handle streaming response...
} catch (error) {
  console.error('API Error:', error.message);
}
```

### Optimize for Token Usage

<Tip>
  Be concise and clear in your prompts to minimize token usage and costs.
</Tip>

```javascript theme={null}
// ❌ Too verbose
const prompt = "I would like you to please help me write a very professional business email that I need to send to my client regarding the project status update...";

// ✅ Concise and clear  
const prompt = "Write a professional email to a client with a project status update.";
```

## Next Steps

<CardGroup cols={2}>
  <Card title="Authentication Guide" icon="key" href="/authentication">
    Learn about API key management, security, and permissions.
  </Card>

  <Card title="Chat API Reference" icon="code" href="/chat-api">
    Explore complete endpoint documentation with all parameters.
  </Card>

  <Card title="Code Examples" icon="terminal" href="/examples/overview">
    View ready-to-use implementations in multiple languages.
  </Card>

  <Card title="Rate Limits" icon="gauge-high" href="/rate-limits">
    Understand usage guidelines and optimization strategies.
  </Card>
</CardGroup>

## Troubleshooting

<AccordionGroup>
  <Accordion title="&#x22;Invalid API key&#x22; Error">
    * Check your API key format: `spj_ai_[64-characters]`
    * Ensure the key is active and not deleted
    * Verify the Authorization header: `Bearer spj_ai_...`
  </Accordion>

  <Accordion title="&#x22;Token limit exceeded&#x22; Error">
    * Check your workspace usage in settings
    * Optimize prompts to use fewer tokens
    * Consider upgrading your plan
  </Accordion>

  <Accordion title="Network/Connection Errors">
    * Verify the API URL is correct
    * Check your internet connection
    * Ensure HTTPS is used, not HTTP
  </Accordion>
</AccordionGroup>

<Note>
  Ready to build amazing AI-powered applications? Start with the [Chat API documentation](/chat-api) or explore our [code examples](/examples/overview) to see what's possible!
</Note>
