Merkium

Search Merkium

API reference

Tool calling

Give the model functions it can call. The model returns a structured call with JSON arguments, your code runs the function, and you send the result back so the model can finish its answer. The format matches OpenAI function tools.

Define tools

Pass a tools array of function definitions. parameters is a JSON Schema object describing the arguments. Set tool_choice to "auto" to let the model decide when to call a tool.

tools
[
  {
    "type": "function",
    "function": {
      "name": "get_weather",
      "description": "Get the current weather for a city",
      "parameters": {
        "type": "object",
        "properties": {
          "city": { "type": "string", "description": "City name" }
        },
        "required": ["city"]
      }
    }
  }
]

The tool call response

When the model calls a tool, the assistant message has content: null, a tool_calls array and finish_reason: "tool_calls". function.arguments is a JSON string that you parse yourself.

200 OK
{
  "id": "chatcmpl-6333e3b52c46",
  "object": "chat.completion",
  "created": 1792542520,
  "model": "ganymede-1.1",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": null,
        "reasoning_content": "The user wants to know the weather in Amsterdam right now. I have a tool available for that.",
        "tool_calls": [
          {
            "id": "chatcmpl-tool-a5e153c98e3c3020",
            "type": "function",
            "function": {
              "name": "get_weather",
              "arguments": "{\"city\": \"Amsterdam\"}"
            }
          }
        ]
      },
      "finish_reason": "tool_calls"
    }
  ],
  "usage": {
    "prompt_tokens": 3018,
    "completion_tokens": 46,
    "total_tokens": 3064
  }
}

Send the result back

Append the assistant message with its tool_calls to the conversation, then add one message per call with role: "tool", the matching tool_call_id and the result as a string. Send the whole conversation again with the same tools.

Second request body
{
  "model": "ganymede-1.1",
  "messages": [
    { "role": "user", "content": "What is the weather in Amsterdam right now?" },
    {
      "role": "assistant",
      "content": null,
      "tool_calls": [
        {
          "id": "chatcmpl-tool-a5e153c98e3c3020",
          "type": "function",
          "function": { "name": "get_weather", "arguments": "{\"city\": \"Amsterdam\"}" }
        }
      ]
    },
    {
      "role": "tool",
      "tool_call_id": "chatcmpl-tool-a5e153c98e3c3020",
      "content": "{\"city\":\"Amsterdam\",\"temperature_c\":12,\"conditions\":\"light rain\"}"
    }
  ],
  "tools": [ ... same tools as before ... ]
}

The model then answers in plain text with finish_reason: "stop":

200 OK
{
  "id": "chatcmpl-c8bea9d60cf4",
  "object": "chat.completion",
  "created": 1792542531,
  "model": "ganymede-1.1",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "\n\nAmsterdam is 12 degrees Celsius right now, with light rain. Grab a jacket.",
        "reasoning_content": "The user asks a simple question about the weather. Simple answer."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": { "prompt_tokens": 3042, "completion_tokens": 34, "total_tokens": 3076 }
}

Full round trip

A complete example with the OpenAI SDKs: request, tool execution and the final answer.

import json
import os
import time
from openai import OpenAI

client = OpenAI(
    base_url="https://chat.merkium.nl/api/v1",
    api_key=os.environ["MERKIUM_API_KEY"],
)

tools = [
    {
        "type": "function",
        "function": {
            "name": "get_weather",
            "description": "Get the current weather for a city",
            "parameters": {
                "type": "object",
                "properties": {"city": {"type": "string", "description": "City name"}},
                "required": ["city"],
            },
        },
    }
]

def get_weather(city):
    # Replace with a real weather lookup.
    return {"city": city, "temperature_c": 12, "conditions": "light rain"}

messages = [{"role": "user", "content": "What is the weather in Amsterdam right now?"}]

# 1. The model decides to call the tool.
first = client.chat.completions.create(
    model="ganymede-1.1", messages=messages, tools=tools, tool_choice="auto"
)
message = first.choices[0].message

if message.tool_calls:
    messages.append({
        "role": "assistant",
        "content": message.content,
        "tool_calls": [call.model_dump() for call in message.tool_calls],
    })

    # 2. Run each tool and send the result back.
    for call in message.tool_calls:
        args = json.loads(call.function.arguments)
        result = get_weather(**args)
        messages.append({
            "role": "tool",
            "tool_call_id": call.id,
            "content": json.dumps(result),
        })

    # 3. The model answers using the tool result.
    # Mind the rate limit: one request every two seconds per key.
    time.sleep(2)
    final = client.chat.completions.create(
        model="ganymede-1.1", messages=messages, tools=tools
    )
    print(final.choices[0].message.content)
else:
    print(message.content)

Streaming tool calls

With "stream": true, tool calls arrive as delta.tool_calls fragments keyed by index. The first fragment for an index carries the id, type and function.name. Later fragments carry pieces of function.arguments to concatenate. The last fragment has finish_reason: "tool_calls".

text/event-stream (tool call chunks)
data: {"id":"chatcmpl-d4c653ae11da","object":"chat.completion.chunk","created":1792542536,"model":"ganymede-1.1","choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"id":"chatcmpl-tool-b3f251b7fcbaabc9","type":"function","function":{"name":"get_weather","arguments":""}}]},"finish_reason":null}]}

data: {"id":"chatcmpl-d4c653ae11da","object":"chat.completion.chunk","created":1792542536,"model":"ganymede-1.1","choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"function":{"arguments":"{\"city\": \""}}]},"finish_reason":null}]}

data: {"id":"chatcmpl-d4c653ae11da","object":"chat.completion.chunk","created":1792542536,"model":"ganymede-1.1","choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"function":{"arguments":"Amsterdam"}}]},"finish_reason":null}]}

data: {"id":"chatcmpl-d4c653ae11da","object":"chat.completion.chunk","created":1792542536,"model":"ganymede-1.1","choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"function":{"arguments":"\"}"}}]},"finish_reason":"tool_calls"}]}

data: [DONE]
calls = {}
stream = client.chat.completions.create(
    model="ganymede-1.1", messages=messages, tools=tools, stream=True
)
for chunk in stream:
    if not chunk.choices:
        continue
    for part in chunk.choices[0].delta.tool_calls or []:
        call = calls.setdefault(part.index, {"id": None, "name": "", "arguments": ""})
        if part.id:
            call["id"] = part.id
        if part.function and part.function.name:
            call["name"] = part.function.name
        if part.function and part.function.arguments:
            call["arguments"] += part.function.arguments

for call in calls.values():
    print(call["id"], call["name"], json.loads(call["arguments"]))

Questions or problems with the API: mail@merkium.nl. Last verified against the live API on October 20, 2026.