Can Mistral Use Tools? Function Calling via OpenAI API
Can Mistral use tools? Mistral's own platform documents function calling, and this API accepts the same OpenAI-style tools format for its own model. Here is how to make it work, with code you can paste.

Key points
- Send a tools array, read tool_calls from the reply, run the function, then return the result with role tool.
- Arguments arrive as a JSON string, so parse and validate them before use.
- JSON mode (response_format json_object) is the simpler choice when you only need structured output.
- Streamed tool calls arrive in pieces and must be stitched together by index.
What you get on this endpoint
If the question behind can mistral use tools is whether you can hand a model a list of functions and get structured calls back, the answer here is yes. This API follows the OpenAI chat completions format, and tool calling is part of it. You describe functions in tools, optionally steer the model with tool_choice, and read tool_calls from the assistant message. Results go back as messages with role: "tool". Streaming works too, with tool calls arriving in the stream.
One clarification before the code. The model behind uncensored is a single open-weight model run by an independent provider. This is not Mistral's official API and not a router to other vendors. If you need Mistral's own hosted models and their platform features, use their platform and read their current documentation. If you want an OpenAI-format endpoint for a model that does not refuse lawful adult requests, keep reading.
The request shape
A tool is a name, a plain-language description and a JSON Schema for the arguments. The description matters more than people expect: it is the text the model reads when deciding whether to call the function. Here is a first call with curl.
curl https://api.mistraluncensored.cc/v1/chat/completions -H "Authorization: Bearer YOUR_API_KEY" -H "Content-Type: application/json" -d '{
"model": "uncensored",
"messages": [{"role": "user", "content": "Where is order A-1042?"}],
"tools": [{
"type": "function",
"function": {
"name": "get_order_status",
"description": "Look up the shipping status of an order by its ID.",
"parameters": {
"type": "object",
"properties": {"order_id": {"type": "string"}},
"required": ["order_id"]
}
}
}]
}'
If the model decides to use the function, the first choice has a message with a tool_calls list instead of plain text. Each entry has an id, the function name, and arguments, which is a string containing JSON. The model does not run anything. Your code runs the function and reports back.
A full tool loop in Python
The loop has three moves: ask, execute, answer. Keep the whole conversation in messages, including the assistant message that holds the tool calls, then append one tool message per call.
import json
from openai import OpenAI
client = OpenAI(
base_url="https://api.mistraluncensored.cc/v1",
api_key="YOUR_API_KEY",
)
def get_order_status(order_id):
return {"order_id": order_id, "status": "shipped", "carrier": "demo"}
tools = [{
"type": "function",
"function": {
"name": "get_order_status",
"description": "Look up the shipping status of an order by its ID.",
"parameters": {
"type": "object",
"properties": {"order_id": {"type": "string"}},
"required": ["order_id"],
},
},
}]
messages = [{"role": "user", "content": "Where is order A-1042?"}]
first = client.chat.completions.create(
model="uncensored", messages=messages, tools=tools
)
msg = first.choices[0].message
if msg.tool_calls:
messages.append(msg)
for call in msg.tool_calls:
args = json.loads(call.function.arguments)
result = get_order_status(**args)
messages.append({
"role": "tool",
"tool_call_id": call.id,
"content": json.dumps(result),
})
final = client.chat.completions.create(
model="uncensored", messages=messages, tools=tools
)
print(final.choices[0].message.content)
else:
print(msg.content)
Loop over every entry in tool_calls, as above, rather than reading only the first. The tool_call_id must match the id of the call you are answering. A mismatch is the most common reason a second request goes wrong. For agents that may need several rounds, wrap the block in a while loop with a hard cap, for example eight turns, so a confused model cannot spin forever and run up your bill.
Steering the model with tool_choice
By default the model decides on its own whether a tool is needed. You can change that with tool_choice.
"auto"lets the model choose between answering and calling."none"blocks tool use for that turn. This is useful for the last turn when you want a plain-text summary.- A named function,
{"type": "function", "function": {"name": "get_order_status"}}, forces that call. Use it when your app always needs the structured arguments, such as extracting fields from a message.
Forcing a call is also a cheap way to get reliable structure for a single step. Because it is an open-weight model, behavior around edge cases depends on your prompt, so test with the messy inputs your users really send, not only the clean example.
Streaming tool calls
With stream: true the reply comes over server-sent events. Tool calls are sent in fragments: the first fragment for a call carries the id and name, later ones carry slices of the arguments string. Each fragment has an index. Join the slices per index and parse only when the stream ends.
calls = {}
stream = client.chat.completions.create(
model="uncensored", messages=messages, tools=tools, stream=True
)
for chunk in stream:
if not chunk.choices:
continue # the usage chunk at the end has no choices
delta = chunk.choices[0].delta
for tc in delta.tool_calls or []:
slot = calls.setdefault(tc.index, {"id": "", "name": "", "arguments": ""})
if tc.id:
slot["id"] = tc.id
if tc.function and tc.function.name:
slot["name"] = tc.function.name
if tc.function and tc.function.arguments:
slot["arguments"] += tc.function.arguments
for slot in calls.values():
args = json.loads(slot["arguments"])
print(slot["name"], args)
Never call json.loads on a half-finished arguments string. Also remember that a streamed request holds one of your concurrency slots until the stream closes. A full key has 8 slots, so a slow consumer that reads the stream lazily can starve your other workers.
Designing tools the model uses well
Most failures with tool calling are design problems, not API problems. A few rules save hours of debugging.
Keep the tool list short. Every definition is sent with every request, and each one gives the model another way to choose wrongly. Five clear tools beat fifteen overlapping ones. If two tools differ only in a parameter, merge them and add an enum field.
Name functions after what they do, with a verb first: search_orders, create_note. Describe parameters in the schema, including units and formats, for example "date in YYYY-MM-DD" or "amount in cents". Mark only the fields you truly need as required, and give the rest sensible defaults in your code so a missing optional field never crashes the call.
Return small, plain results. A tool that sends back a 50,000-character database dump means those tokens are sent as input again on every later turn that carries the history. Trim to the fields the model needs, and return a short error string when something fails so the model can explain the problem or try another approach. For example, return {"error": "order not found"} and let the model tell the user, instead of raising an exception that ends the conversation.
Finally, decide which tools are safe to run without a human. Reading data is low risk. Sending an email, deleting a record or spending money deserves a confirmation step in your own code, whatever the model says it wants to do.
JSON mode or tools?
The two features overlap, and picking the right one saves code.
| You need | Use | Why |
|---|---|---|
| A reply shaped as one JSON object | JSON mode | One request, no loop, no function to run |
| The model to trigger actions in your code | Tool calling | The model picks which function and fills the arguments |
| Extraction from text into fields | Either | Forced tool call gives a schema; JSON mode is simpler to write |
To turn JSON mode on, add response_format and say in the prompt what shape you want:
resp = client.chat.completions.create(
model="uncensored",
response_format={"type": "json_object"},
messages=[
{"role": "system", "content": "Reply with a JSON object with keys title and tags (a list of strings)."},
{"role": "user", "content": "A short story about a lighthouse keeper who finds a locked door."},
],
)
data = json.loads(resp.choices[0].message.content)
JSON mode gives you valid JSON syntax, but it does not enforce your keys. Check that the fields you need are present, and retry once if they are not.
Common mistakes and how to fix them
- Parsing arguments as an object. They are a string. Call
json.loads, and wrap it in a try block, because a model can produce invalid JSON on rare occasions. - Dropping the assistant message. The second request must include the assistant turn that contains
tool_calls, then the tool messages. Skipping it breaks the pairing. - Vague descriptions. If two tools sound alike, the model will mix them up. Say what each does and when not to use it.
- Trusting arguments. Validate IDs, ranges and paths before acting. Treat model output as untrusted input, especially when a function can write data or spend money.
- Hitting limits. A 429 with code
rate_limitedmeans too many requests per minute;concurrencymeans too many at once. A 429 with aRetry-After: 5header is temporary overload, so wait and retry.
The docs cover the base URL and key format, and the pricing page explains how tool turns are billed: the same $0.15 and $0.50 per 1M tokens, counted on the whole prompt. Tool definitions travel in the prompt, so expect them to count as input tokens and keep descriptions tight. If you do not have a key yet, create one here; the one-click trial credit is enough to test a full loop.
More guides
Questions and answers
Can Mistral models use tools?
Mistral's own platform documents function calling, so check their docs for details. On this API, tool calling follows the OpenAI format for the single model it serves.
Does streaming work with tool calls?
Yes. Tool call fragments arrive in the stream with an index, and you join the arguments pieces before parsing.
Is JSON mode supported?
Yes. Set response_format to {"type": "json_object"} and describe the shape you want in the prompt.
How are tool calls billed?
Like any request: input tokens at $0.15 per 1M and output tokens at $0.50 per 1M. Tool definitions are sent in the prompt, so expect them to count as input.
Which SDK should I use?
Any OpenAI SDK works once you set the base URL and key. The examples here use the official Python package.
Your key is one form away
Create an account, copy the key, change the base URL. That is the whole setup.