Skip to main content
The chat completions endpoint powers conversational AI by accepting a structured array of messages instead of a raw prompt. Each message has a role and content, and the model uses the full conversation history to generate the next reply. This makes it the right choice for chatbots, AI assistants, and any task that benefits from back-and-forth context.

Message Roles

Every message in the messages array has a role field that tells the model who is speaking. A well-crafted system message is the single most effective way to control how the model responds. Think of it as a standing instruction the model always has in view.

Send a Chat Completion Request

Make a POST request to https://api.swytcho.com/v1/chat/completions with at least one user message.

Managing Conversation History

The Swytcho API is stateless — it does not store conversation history between requests. To maintain context across turns, you append each new message (both user input and the model’s reply) to your local messages array and send the full history with every request. Here is a complete multi-turn conversation example:
Python
Each call to chat() sends the complete history, so the model can reference earlier turns when answering follow-up questions.

Best Practices

System Prompt Design

A strong system prompt does three things: establishes the model’s role, sets the tone, and defines any hard constraints.
Be explicit about what the model should and should not do. Vague instructions produce vague behavior.

Context Window Management

Every model has a maximum context window measured in tokens. As conversation history grows, you must manage it to avoid hitting the limit. Common strategies:
  • Sliding window — keep only the last N messages (plus the system prompt)
  • Summarization — periodically summarize older turns into a single assistant message
  • Selective trimming — drop low-information exchanges while keeping key facts
Token count accumulates across every message in the messages array — system, user, and assistant alike. A 10-turn conversation can easily consume thousands of tokens before a single new token is generated. Monitor usage.total_tokens in each response to track consumption and trigger your context management strategy before you hit the model’s limit.