Tools & structured output
Function calling and JSON output work as in the OpenAI API on every model whose catalog entry declares the capability.
Function calling
import os from openai import OpenAI client = OpenAI(base_url="https://gridport.ai/v1", api_key=os.environ["GRIDPORT_API_KEY"]) tools = [{"type": "function", "function": {"name": "get_weather", "description": "Current weather for a city", "parameters": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]}}}] r = client.chat.completions.create(model="deepseek-ai/DeepSeek-V4-Flash", messages=[{"role": "user", "content": "Weather in Paris?"}], tools=tools) call = r.choices[0].message.tool_calls[0] print(call.function.name, call.function.arguments) # get_weather {"city": "Paris"} # run the tool, then append the result as a "tool" message and call again
finish_reason is tool_calls when the model wants a tool. Streaming delivers tool_calls as deltas with an index; concatenate the arguments per index. parallel_tool_calls is honoured by models that declare it.
JSON mode and JSON schema
import json # client as above r = client.chat.completions.create(model="deepseek-ai/DeepSeek-V4-Flash", messages=[{"role": "user", "content": "Give me a user with name and age as JSON."}], response_format={"type": "json_object"}) user = json.loads(r.choices[0].message.content)
response_format json_object needs the model capability json_mode; json_schema needs structured_output. Asking a model without the capability returns 400 unsupported_parameter with param response_format, never a silently ignored setting. Errors
Which models support what
The models page lists capabilities per model, and GET /v1/models/{id} returns them under tf.capabilities. The Playground greys out tools and response_format when the selected model lacks them. Browse models