How do I set temperature or top_p in Python?
Pass temperature (0 to 2) or top_p (above 0, up to 1). Lower temperature makes replies more predictable; higher makes them more varied.
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.gateway.clatterlabs.xyz/v1",
api_key=os.environ["CLATTER_API_KEY"],
default_headers={"X-Clatter-Account": os.environ["CLATTER_ACCOUNT_ID"]},
)
r = client.chat.completions.create(
model="supercosmos-flash",
messages=[{"role": "user", "content": "Suggest a name for a coffee shop."}],
temperature=1.2,
)
print(r.choices[0].message.content)
Change one of the two, not both. For extraction or code, keep temperature low.
The client setup above (base URL, key and the X-Clatter-Account header) is the same in every Python example; see Set up the Python SDK. Full parameter list: Create a chat completion.
Good to know#
- Retry only
429and 5xx errors, with backoff; honourRetry-Afterwhen it's sent. Which errors to retry - Keep keys on your server, never in a browser or mobile app. Why
- Every response has an
X-Request-Id; log it so a request can be found later. Why log it
Still need help?#
- General support: support@clatterlabs.com or team@clatterlabs.xyz
- Infrastructure questions, or permanent deletion of your data (your whole account or one service): infrastructure@clatterlabs.xyz
We usually reply within the first hour, and always within 24 hours. A full support team is with you.
Related articles
- How do I set up the OpenAI Python SDK for the Model API?
- How do I force or block tool use in Python?
- How do I limit the length of a reply in Python?
- What happens if I send temperature 3 or top_p 0?
- Can credits top up automatically?Plans & billing
- Should I change temperature or the tier to improve answers?SuperCosmos models
Still need help?
Tried the steps above and still stuck? Email us. We usually reply within the first hour, and always within 24 hours. A full support team is with you.
Infrastructure questions, or permanent deletion of your data
infrastructure@clatterlabs.xyzFor deleting your whole account or the data of one service.