How do I force or block tool use in Python?
tool_choice controls whether the model may call tools: auto (default), none, required, or one named function.
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": "Paris"}],
tools=tools, # as in the tool calling example
tool_choice={"type": "function", "function": {"name": "get_weather"}},
)
print(r.choices[0].message.tool_calls[0].function.arguments)
Use "required" when the model must call some tool, and "none" to get a plain text answer even though tools are defined.
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#
- Every response has an
X-Request-Id; log it so a request can be found later. Why log it - If calls fail unexpectedly, check status.clatterlabs.com before debugging further.
- Every call shows in Console › Logs and Usage as Model API, with its price. See what you spent
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
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.