Skip to main content
POST

Overview

The POST /chat endpoint is the primary way to interact with SundayPyjamas AI models. It accepts a conversation history and returns an AI-generated response as a streaming text.
All responses are streamed in real-time for better user experience in conversational applications.

Authentication

string
required
Bearer token with your API key. Format: Bearer spj_ai_your_api_key_here

Request Body

Array<Message>
required
Array of conversation messages. Must contain at least one message with valid content.
string
default:"llama-3.3-70b-versatile"
AI model to use for generating the response. Currently available models:
  • llama-3.3-70b-versatile - High-quality general-purpose model (default)

Response

Headers

The response includes the following headers for streaming:

Body

string
Streaming text response from the AI model. The complete response is built by concatenating all streamed chunks.

Examples

Basic Request

With System Message

Multi-turn Conversation

Specifying Model

Content Generation

Error Responses

400 Bad Request

401 Unauthorized

403 Forbidden

429 Too Many Requests

500 Internal Server Error

Streaming Implementation

JavaScript/TypeScript

Python

Go

Request Validation

Message Array Requirements

Valid: Contains required fields with proper types
Invalid: Empty messages array
Invalid: Missing content field
Invalid: Empty content string
Invalid: Invalid role value

Content Length Limits

Very long requests may hit token limits. Consider breaking large content into smaller chunks or summarizing previous context.
Practical limits:
  • Single message: ~10,000 characters recommended
  • Total conversation: ~20,000 characters for optimal performance
  • Token estimation: ~4 characters per token

Rate Limiting Details

Token Usage

Input + output tokens count toward workspace limits

Request Rate

No hard limits, but monitored for abuse

Concurrent Requests

Multiple simultaneous requests supported

Fair Usage

Excessive usage may be throttled

Optimization Tips

To optimize your usage:
  • Use clear, concise prompts
  • Trim conversation history to relevant context
  • Batch similar requests when possible
  • Monitor token usage through workspace analytics

Testing with Different Tools

Postman

HTTPie

Insomnia

Performance Considerations

Response Times

Typical response times vary based on:
  • Request complexity: Simple queries respond faster
  • Response length: Longer responses take more time
  • Server load: Peak times may have slightly longer latencies
Expected ranges:
  • Simple queries: 1-3 seconds
  • Complex content generation: 3-10 seconds
  • Very long responses: 10-30 seconds

Best Practices

  • Use specific, focused prompts
  • Limit conversation history to relevant context
  • Request shorter responses when appropriate
  • Use streaming to show progress to users
  • Reuse HTTP connections when possible
  • Implement proper connection pooling
  • Handle network interruptions gracefully
  • Use appropriate timeouts for your use case

Next Steps

Code Examples

See complete implementation examples in multiple languages

Error Handling

Learn comprehensive error handling patterns

Rate Limits

Understand usage optimization and monitoring

Authentication

Manage API keys and security best practices