Define a tool
Tool support depends on the model. The gateway forwards tool definitions and returns the model’s requested calls. It does not execute your functions.
{
"model": "deepseek-v4-1-flash",
"messages": [{"role":"user","content":"What is the weather in London?"}],
"max_tokens": 512,
"tools": [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a city.",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"]
}
}
}],
"tool_choice": "auto"
}Return tool results
Parse function.arguments as JSON and validate them against your application’s schema and permissions. Append the full assistant message containing the tool call, then append a tool result for each matching tool_call_id. Send the updated history back to the chat endpoint.
{
"role": "tool",
"tool_call_id": "call_id_from_the_assistant",
"content": "{\"city\":\"London\",\"temperature_c\":18}"
}In streaming mode, assemble all argument fragments for a tool call before parsing or executing it. Function arguments are generated input, not an authorization to perform an action.
Request JSON output
For models that support JSON mode, include response_format and explicitly ask for JSON in the messages. Validate the returned content before using it.
{
"model": "deepseek-v4-1-flash",
"messages": [{"role":"user","content":"Return a JSON object with a greeting field."}],
"max_tokens": 256,
"response_format": {"type":"json_object"}
}JSON-schema enforcement and strict mode vary by model. The specialized flock-this-that model requires a JSON schema with one string-enum property and is intended for typed decisions, not general chat. Its requirements are listed in its model metadata.