Skip to main content

Overview

The Chat API is the core endpoint for conversational AI, content generation, and text completion. It provides access to powerful language models with streaming responses for real-time interactions.
This reference includes all request/response schemas, parameters, and interactive examples you can test directly.

Base URL

https://suite.sundaypyjamas.com/api/v1

Authentication

All API requests require authentication using your API key:
Authorization: Bearer spj_ai_your_api_key_here

Endpoints

Quick Example

Here’s a simple example to get you started:
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."
      }
    ]
  }'

Common Patterns

System Messages

Use system messages to set the AI’s behavior and context:
{
  "messages": [
    {
      "role": "system",
      "content": "You are a helpful assistant that writes professional emails."
    },
    {
      "role": "user",
      "content": "Write a follow-up email after a job interview."
    }
  ]
}

Multi-turn Conversations

Include conversation history for context:
{
  "messages": [
    {
      "role": "user",
      "content": "What's the weather like?"
    },
    {
      "role": "assistant",
      "content": "I don't have access to real-time weather data..."
    },
    {
      "role": "user",
      "content": "What about general weather patterns?"
    }
  ]
}

Content Generation

Structure prompts for specific content types:
{
  "messages": [
    {
      "role": "system",
      "content": "You are a content marketing expert. Write engaging blog posts with clear structure and actionable insights."
    },
    {
      "role": "user",
      "content": "Write a blog post about remote work productivity tips for software developers. Target length: 1000 words."
    }
  ]
}

Error Handling

All errors return a consistent format:
{
  "error": "Human-readable error message"
}
Common HTTP status codes:
Invalid request format or missing required fields.Example:
{
  "error": "Messages array is required"
}
Invalid or missing API key.Example:
{
  "error": "Invalid API key"
}
Token limit exceeded or insufficient permissions.Example:
{
  "error": "Token limit exceeded"
}
Rate limit exceeded.Example:
{
  "error": "Rate limit exceeded"
}
Server-side error occurred.Example:
{
  "error": "Failed to generate response"
}

Rate Limits

Token-based Limits

Usage measured in tokens (input + output)

Request Rate

No hard limits, but monitored for abuse

Workspace Quotas

Monthly token limits per workspace

Concurrent Requests

Multiple simultaneous requests supported
For detailed rate limit information, see the Rate Limits guide.

Best Practices

Request Optimization

  • Be specific and clear in your instructions
  • Use system messages to set context once
  • Keep conversation history relevant and concise
{
  "messages": [
    {
      "role": "system",
      "content": "You write concise, professional emails."
    },
    {
      "role": "user",
      "content": "Write a project status update email to stakeholders."
    }
  ]
}
  • Trim old messages to stay within token limits
  • Keep only relevant context for the current task
  • Use consistent message formatting
function trimConversation(messages, maxTokens = 2000) {
  // Keep system message and recent relevant messages
  const systemMessage = messages.find(m => m.role === 'system');
  const recentMessages = messages.slice(-10); // Last 10 messages
  
  return systemMessage 
    ? [systemMessage, ...recentMessages.filter(m => m.role !== 'system')]
    : recentMessages;
}
  • Always check response status codes
  • Implement retry logic for transient errors
  • Provide user-friendly error messages
async function makeRequest(messages) {
  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);
    }

    return response;
  } catch (error) {
    console.error('API request failed:', error);
    throw error;
  }
}

SDK Libraries

JavaScript/TypeScript

Official and community libraries for Node.js and browsers

Python

Async and sync clients with full type support

Go

Community-maintained Go client library
Official SDKs are coming soon! For now, use the examples in our code examples section.

Testing Tools

API Testing

Use tools like Postman, Insomnia, or curl for testing:
# Test endpoint availability
curl -X POST https://suite.sundaypyjamas.com/api/v1/chat \
  -H "Authorization: Bearer your_api_key" \
  -H "Content-Type: application/json" \
  -d '{"messages": [{"role": "user", "content": "test"}]}' \
  -w "\nStatus: %{http_code}\nTime: %{time_total}s\n"

Load Testing

For production readiness testing:
# Simple load test with ab (Apache Bench)
ab -n 100 -c 10 -T application/json \
   -H "Authorization: Bearer your_api_key" \
   -p test_payload.json \
   https://suite.sundaypyjamas.com/api/v1/chat

Support

Documentation

Comprehensive guides and examples

Community

Join discussions with other developers

Support

Contact support through your workspace

Status Page

Monitor API status and uptime

Next Steps