Synapse
Esc
  • Docs
    Make your first request↵
  • Streaming
  • Function calling
  • Errors and rate limits
  • Pages
    Home
  • Models
  • Pricing and cost calculator
  • Rate limits by tier
  • Enterprise, SOC 2 and data retention
  • Changelog

docs · guides

Function calling

Describe your functions with JSON Schema and the model decides when to call them. Arguments are validated against the schema before they reach you.

Declaring tools#

Each tool has a name, a description the model reads, and parameters as a JSON Schema object.

tools = [{
    "name": "get_weather",
    "description": "Current weather for a city",
    "parameters": {"type": "object", "properties": {"city": {"type": "string"}}},
}]

reply = client.chat.create(model="syn-flash", messages=messages, tools=tools)

if reply.tool_calls:
    call = reply.tool_calls[0]
    print(call.name, call.arguments)  # get_weather {"city": "Lisbon"}

Returning results#

Run the function yourself, then send the result back as a tool message with the same tool_call_id. The model continues from there.

json
{
  "role": "tool",
  "tool_call_id": "call_41xq",
  "content": "{\"temp_c\": 22, \"sky\": \"clear\"}"
}

Parallel calls#

Flash, Code, Pro and Ultra can return several tool calls in one turn. Run them concurrently and return every result before the next request.

Forcing a tool#

Set tool_choice to a tool name to force that call, or to "none" to stop the model calling tools at all.