Is it Gemma, and does it matter
Be clear on what you are getting. This site does not host Google's Gemma. It hosts one open-weight model, run by an independent provider and tuned to answer without content refusals for lawful adult use. The reason a page about gemma 3 function calling belongs here is the interface: you get the same tool-calling fields the OpenAI SDK uses, so code written for function calling elsewhere moves over.
If you need Gemma itself, for example to run its weights in your own environment, check Google's documentation for what each variant supports. If you need function calling plus an endpoint that does not refuse lawful adult content, continue here. The model ID is uncensored and the base URL is https://api.gemmauncensored.com/v1.
Choose between tools and JSON mode
Many applications do not need an agent at all. If the job is to turn a message into a record, a single JSON mode request is simpler to build and to debug, and it costs less because there are no tool definitions to resend.
Function calling is one of two ways to get structure out of a model. Pick the lighter one that does the job.
| Goal | Use | Why |
|---|---|---|
| Extract fields from text | JSON mode | One request, no loop, easy to parse |
| Let the model decide whether to act | Tools | It can answer in text or request a function |
| Chain steps, such as search then answer | Tools | Results return as tool messages in a loop |
| Classify into fixed labels | JSON mode | Cheaper, no schema overhead per call |
JSON mode is enabled with response_format: {"type":"json_object"}. Tell the model in the prompt which keys you want, since JSON mode guarantees valid JSON syntax, not your particular schema. Tool definitions add tokens to every request, so skip them when you do not need actions.
Define a function the model can use
Think about the user's phrasing too. People say "tomorrow at nine" or "next Friday", and your schema asks for ISO 8601. Either tell the model the current date and time zone in the system message so it can convert, or accept a loose string and parse it in your own code. Giving the model the current date is cheap and removes a whole class of wrong dates.
The schema is part of the prompt. The model reads the name, the description and the property descriptions, and it writes arguments to match. Treat them as documentation for a new colleague.
- Use verb-first names:
search_notes,create_reminder. - Write what the function does and when to use it, in one or two sentences.
- Give every property a type and a short description. Use
enumfor closed sets. - Mark only truly needed fields as
required. - Keep each function narrow. Two small functions beat one with a mode switch.
{
"type": "function",
"function": {
"name": "create_reminder",
"description": "Create a reminder. Use when the user asks to be reminded of something.",
"parameters": {
"type": "object",
"properties": {
"text": {"type": "string", "description": "What to remind about"},
"when": {"type": "string", "description": "ISO 8601 date and time"},
"priority": {"type": "string", "enum": ["low", "normal", "high"]}
},
"required": ["text", "when"]
}
}
}A Node.js loop that handles several calls
The model can return more than one entry in tool_calls in a single reply, so loop over the list and answer every id. Skipping one leaves the conversation in a state the next request may reject.
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.gemmauncensored.com/v1",
apiKey: process.env.API_KEY,
});
const impl = {
create_reminder: ({ text, when, priority = "normal" }) =>
({ ok: true, text, when, priority }),
};
const messages = [{ role: "user", content: "Remind me to call Dana tomorrow 9am." }];
for (let step = 0; step < 5; step++) {
const res = await client.chat.completions.create({
model: "uncensored",
messages,
tools,
tool_choice: "auto",
});
const msg = res.choices[0].message;
messages.push(msg);
if (msg.tool_calls === undefined || msg.tool_calls.length === 0) {
console.log(msg.content);
break;
}
for (const call of msg.tool_calls) {
let content;
try {
const fn = impl[call.function.name];
if (fn === undefined) throw new Error("unknown function " + call.function.name);
content = JSON.stringify(fn(JSON.parse(call.function.arguments)));
} catch (err) {
content = JSON.stringify({ error: String(err.message) });
}
messages.push({ role: "tool", tool_call_id: call.id, content });
}
}
Here tools holds the array with the schema from the previous section. The try block turns any failure into data the model can read, which is the safest way to let it recover.
Validate before you execute
Model output is untrusted input, in the same way a web form is. Before you run a function, check the arguments against your schema with a validator such as Ajv in JavaScript or Pydantic in Python. Reject unknown keys, wrong types and out-of-range values.
A practical pattern is to keep a registry that pairs each function with its validator and a risk level, and to have one dispatch function that looks up the name, validates, checks the risk and only then calls the code. Every tool call then passes through the same gate, and you have one place to add logging.
Separate functions by risk. Reading data is low risk and can run automatically. Sending an email, spending money or deleting records should wait for an explicit confirmation from the user in your own interface. The model can propose the action, but your code decides. Never pass model-written strings to a shell, a SQL string or eval.
When validation fails, return the problem as the tool result, for example {"error": "when must be ISO 8601"}. A short error with the expected format usually gets a corrected call on the next pass.
Debugging checklist
- No tool call returned. Is the description clear about when to use it? Try
tool_choiceset to the function name to confirm the schema works at all. - Wrong argument types. Add an
enumor an example in the property description. - Loop never ends. Cap the number of passes and log each call. A repeating call with identical arguments means your tool result does not answer the question.
- Status 429. Code
rate_limitedmeans more than 300 requests per minute;concurrencymeans more than 8 at once. ARetry-After: 5header marks temporary overload, so wait that long and retry. Trial keys have lower limits: 2 concurrent and 60 per minute. - Unexpected cost. Print the usage object after each pass. Check the
X-Balance-USDresponse header to see your balance after a request.
Keep logs while you build. Record the request id from the X-Request-Id response header, the function name, the raw arguments and the result. When something goes wrong a week later, those four fields let you reproduce the problem and, if you contact support, point to the exact request.
Parameters such as temperature, top_p, stop and seed are passed through. For calls, a temperature around 0.2 and a fixed seed make failures reproducible. See the quickstart notes for the full parameter list, and the developer guide to using the API for a broader walkthrough.
Cost and getting started
Prices are $0.15 per 1M input tokens and $0.50 per 1M output tokens. A typical agent turn with tools resends the history and schemas, so input dominates. Example: a support bot handles one ticket in 4 passes, each with 3,000 prompt tokens and 200 output tokens. Input is 12,000 tokens, or 12,000 / 1,000,000 x $0.15 = $0.0018. Output is 800 tokens, or 800 / 1,000,000 x $0.50 = $0.0004. A ticket costs $0.0022, so 1,000 tickets cost $2.20.
Cutting that bill is mostly about input. Shorten function descriptions, send only the tools relevant to the current screen, and trim old turns from the history once they no longer matter. A request that carries 8 tool definitions when 2 would do pays for the extra 6 on every pass.
To start, sign up with Google or with email and password, then claim the $0.50 trial on the API key page. One click, no card, valid for 7 days. Paid top-ups start at $20 and are covered on the pricing page. The credit does not expire, and failed or refused requests are not charged. Prompts are not used for training.
