Implementation
1. Setup and Authentication
C1 API is designed to be fully compatible with the OpenAI Chat Completions API. The recommended way to interact with the endpoint is to use the official OpenAI client library for your preferred language. To get started, you need to initialize the client with your Thesys API Key and the C1 Base URL.You can create a new API key from Developer Console
main.py
2. Structuring the API Request
The core of every request is themessages
array, which provides the conversational context to the model.
The array consists of one or more message objects, each with a role
and content
:
role: 'system'
: Provides high-level instructions or context for the AI. This is typically the first message in the array.role: 'user'
: Represents a prompt or message from the end-user.role: 'assistant'
: Represents a previous response from the AI.
user
and assistant
messages in the array before adding the latest user prompt.
model
you wish to use. For a full list of available models, see the Models and Pricing guide.
3. Implementation Patterns
Your implementation will depend on whether you are building a conversational application that needs to remember context or a standalone tool that handles one-off requests.In a conversational pattern, your backend must store and manage the history of the conversation. On each new request, you retrieve the history, add the new user message, and then save the assistant’s response to persist the context.The following is a simplified but complete example using an in-memory array for history. In a production application, you would replace this with a database.
main.py (FastAPI)
C1 API Reference
- Endpoint:
POST /chat/completions
- Authentication: The API uses
Authorization: Bearer <THESYS_API_KEY>
. The client libraries handle this header for you.
Supported Parameters
The C1 API supports the following standard OpenAI chat completion parameters:model
(string, required): The model ID to use for the generation.messages
(array, required): A list of message objects that form the conversation history.stream
(boolean, optional): Iftrue
, the response will be streamed back in chunks.temperature
(number, optional): Controls randomness. Defaults to 1.0.max_tokens
(integer, optional): The maximum number of tokens to generate.top_p
(number, optional): Nucleus sampling parameter.stop
(string or array, optional): Sequences where the API will stop generating further tokens.