Skip to main content

Create Chat Completion

Create a chat completion with AI that understands activist strategy.
This endpoint is 100% OpenAI SDK compatible. Just change the base URL!

Endpoint

Required Scopes

  • chat:write - Create chat completions

Request Body

Message Object

Response

Non-Streaming Response

Streaming Response

When stream: true, returns Server-Sent Events (SSE):

Examples

Basic Completion

With System Message

Set context and persona with a system message:

Multi-Turn Conversation

Method 1: Send Full History

Method 2: Use Session ID

With Theory of Change

Align AI responses with your strategic framework:
Theory Positions:
  • Voluntarism {x: -1, y: -1} - Grassroots mobilization
  • Structuralism {x: 1, y: -1} - Policy/systems change
  • Subjectivism {x: -1, y: 1} - Cultural transformation
  • Theurgism {x: 1, y: 1} - Faith-based activism
See the Theory of Change Guide for details.

Streaming Response

Get real-time token-by-token responses:
See the Streaming Guide for advanced patterns.

Temperature Control

Control response randomness:

Max Tokens

Limit response length:

Error Responses

400 Bad Request

401 Unauthorized

402 Payment Required

429 Too Many Requests

Pricing

Chat is billed per token at $0.08 per 1,000 tokens. Token Estimation:
  • ~750 words = 1,000 tokens
  • Average message: 50-200 tokens
  • Typical conversation: 500-2,000 tokens (0.040.04-0.16)
Example costs:

Rate Limits

Best Practices

1. Use System Messages

Set context with system messages for better responses:

2. Manage Context Window

Keep conversations under 128K tokens. See best practices guide.

3. Use Streaming for UX

Stream responses for better perceived performance:

4. Handle Errors Gracefully

Always implement retry logic and error handling. See Error Handling Guide.

Next Steps

Streaming

Use streaming for real-time responses

List Sessions

List chat sessions

Theory of Change

Align AI with your strategic approach

Error Handling

Handle errors gracefully