Message Roles
Every message in themessages 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 aPOST 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 localmessages array and send the full history with every request.
Here is a complete multi-turn conversation example:
Python
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.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.