Core Concepts

Chat & Messages API

The Chat API is the primary interface for conversations, reasoning, and code generation with Cortiqa models like openai/gpt-oss-120b. It supports multi-turn dialogues, system instructions, real-time streaming, and tool calls.


Basic Request

chat.py
1import cortiqa
2
3client = cortiqa.Client()
4
5response = client.chat.create(
6 model="openai/gpt-oss-120b",
7 messages=[
8 {"role": "user", "content": "What is machine learning?"}
9 ],
10 temperature=0.7
11)
12
13print(response.content)

Request Body

ParameterTypeRequiredDescription
modelstringYesModel ID, e.g. openai/gpt-oss-120b or cortiqa/falin-1
messagesarrayYesArray of role/content objects (system, user, assistant)
max_tokensintegerNoMaximum tokens to generate (up to 131K context)
temperaturefloatNoSampling temperature (0.0 to 2.0). Default: 0.7
top_pfloatNoNucleus sampling probability threshold
streambooleanNoEnable SSE token streaming. Default: false
toolsarrayNoList of tool definitions for function calling
stoparrayNoCustom stop sequences

Response Format

Response JSON
{
  "id": "chatcmpl-01JHE7N9",
  "object": "chat.completion",
  "created": 1726982400,
  "model": "openai/gpt-oss-120b",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Machine learning is a subset of artificial intelligence where algorithms learn patterns from data..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 12,
    "completion_tokens": 84,
    "total_tokens": 96
  }
}

Multi-turn Conversations

Include the historical conversation turns to maintain context:

multi_turn.py
1response = client.chat.create(
2 model="openai/gpt-oss-120b",
3 messages=[
4 {"role": "user", "content": "What is Python?"},
5 {"role": "assistant", "content": "Python is a high-level, readable programming language..."},
6 {"role": "user", "content": "What are its 3 biggest advantages for AI development?"}
7 ]
8)
9print(response.content)

System Prompts

Provide a system message at index 0 to steer model persona and formatting rules:

system_prompt.py
response = client.chat.create(
    model="openai/gpt-oss-120b",
    messages=[
        {"role": "system", "content": "You are a senior systems engineer at Cortiqa. Respond strictly in valid JSON."},
        {"role": "user", "content": "List 3 Linux diagnostic commands."}
    ]
)
System Prompt Best Practices
System prompts help ensure consistent tone, JSON output formatting, and domain constraints. Explore our System Prompts guide for advanced patterns.
Was this page helpful?