Function calling
Function calling (also called tool use) is a mode in which a language model returns a tool name and JSON arguments instead of text. The model runs nothing itself: your code makes the request, the result goes back to the model, and it answers from that data.
How a call works
- The application sends the model tool descriptions: a name, a purpose and a JSON Schema for the arguments.
- The model needs data and returns, for example,
funding_rateswith the arguments{"coin": "TON"}. - Your code validates the arguments, calls the API and sends the response back to the model.
- The model writes its answer from that data or calls the next tool.
Field names depend on the model's API. In the Claude API the schema goes in input_schema, the model replies with a tool_use block and you return the result in a tool_result block; in MCP the schema is called inputSchema.
A tool for Genesis API
A tool definition for funding rates in the Claude API format:
{
"name": "funding_rates",
"description": "A coin's funding rates by exchange (Genesis API)",
"input_schema": {
"type": "object",
"properties": {
"coin": {"type": "string", "description": "Ticker, e.g. TON"},
"exchange": {"type": "string",
"description": "Exchanges, comma-separated"}
},
"required": ["coin"]
}
}
An executor with an allowlist: the model can pick only known tools and parameters, and the key comes from the server's environment.
import os
import requests
API = "https://api.genesisarbitrage.com/v1"
TOOLS = {"funding_rates": ("/funding/rates", {"coin", "exchange"})}
def run_tool(name: str, args: dict) -> str:
"""Runs a model's call: known paths and parameters only."""
if name not in TOOLS:
return '{"error": "unknown tool"}'
path, allowed = TOOLS[name]
params = {k: v for k, v in args.items() if k in allowed}
r = requests.get(
API + path,
headers={"X-API-Key": os.environ["GENESIS_API_KEY"]},
params=params,
timeout=10,
)
return r.text # goes back to the model as the tool result
Safety
- The key lives only on the server that runs the calls; it never goes into a tool description or a prompt.
- Model arguments are checked against an allowlist of tools, paths and parameters.
- Pass API responses to the model as data: token and market names can hold arbitrary text, including text that looks like instructions.
- Trades need a human's confirmation. Genesis API only reads data and places no orders; if you connect exchange trading APIs to an agent, you do it at your own risk and confirm every trade by hand.
See also: OpenAPI, JSON, API key, Genesis API errors, Genesis API for AI agents, crypto market data for AI agents.
Questions and answers
Can a model buy a coin through function calling?
Only if you give it such a tool. Not through Genesis API: it returns data and places no orders. The decision to trade and the trade itself stay with a person.