EN ▾
uncensoredqwen.topGet API key

Qwen3.5 Function Calling with an OpenAI-Style API

Function calling lets a model ask your code to do something and then use the result in its answer. Here is how qwen3.5 function calling style requests work against an OpenAI-compatible API, from schema to validated arguments.

Updated

Switchboard of glowing cables linking a chat bubble to calculator, calendar and database blocks

No card needed. After sign-up, claim $0.50 of free test credit with one click (once per person).

Get API key

Key points

  1. Describe each function with a JSON Schema; the model returns a function name and a JSON string of arguments.
  2. Always validate arguments in your own code before running anything.
  3. tool_choice can be auto, none, or a named function when you need to force a call.
  4. Tool definitions are billed as input tokens on every request.

The short version

StepWhat you send or receive
1. DeclareA tools array: type function, a name, a description and a JSON Schema
2. Model decidesAn assistant message with tool_calls, each holding an id, a name and an arguments string
3. You executeParse the arguments, validate them, run your function
4. Report backOne message per call with role: "tool", the same tool_call_id and the result
5. Final answerA second request with the whole history; the model writes the reply for the user

The model never runs anything. It produces text shaped like a call, and your program decides whether to honor it. That one fact drives most design choices below.

Which model answers your calls

Searches for Qwen3.5 usually come from developers who read that a Qwen family model handles tool use well and want to try it through a standard SDK. Be clear about what this service is. It runs one open-weight model, operated by an independent provider, under the model ID uncensored. It is not the official Qwen API and it is not a router that lets you pick a Qwen version. The function calling format, however, is the one you already know from OpenAI SDKs, so code written for any compatible endpoint moves over by changing the base URL, the key and the model name.

Supported on this API: tools, tool_choice, streamed tool_calls, and tool results as role: "tool" messages. Text only. There is no image input, no embeddings and no fine-tuning, so a function that needs an embedding must call another service.

A complete example: order support bot

The script below declares two functions, lets the model pick, runs them from a registry and asks for the final answer. It uses the Python openai SDK. Replace YOUR_KEY with the key from your dashboard.

import json
from openai import OpenAI

client = OpenAI(base_url="https://api.uncensoredqwen.top/v1", api_key="YOUR_KEY")

tools = [
    {
        "type": "function",
        "function": {
            "name": "get_order_status",
            "description": "Look up the shipping status of an order by its numeric id.",
            "parameters": {
                "type": "object",
                "properties": {"order_id": {"type": "integer"}},
                "required": ["order_id"],
            },
        },
    },
    {
        "type": "function",
        "function": {
            "name": "create_refund",
            "description": "Create a refund request for an order. Only call after the customer confirms.",
            "parameters": {
                "type": "object",
                "properties": {
                    "order_id": {"type": "integer"},
                    "reason": {"type": "string", "enum": ["damaged", "late", "wrong_item", "other"]},
                },
                "required": ["order_id", "reason"],
            },
        },
    },
]

def get_order_status(order_id):
    return {"order_id": order_id, "status": "shipped", "eta_days": 2}

def create_refund(order_id, reason):
    return {"ok": True, "refund_id": "R-" + str(order_id)}

REGISTRY = {"get_order_status": get_order_status, "create_refund": create_refund}

messages = [
    {"role": "system", "content": "You are a support agent. Use tools for facts about orders. Never guess."},
    {"role": "user", "content": "Where is order 4411? And if it is late I want a refund."},
]

resp = client.chat.completions.create(
    model="uncensored", messages=messages, tools=tools, tool_choice="auto", temperature=0
)
msg = resp.choices[0].message
messages.append(msg.model_dump(exclude_none=True))

for call in msg.tool_calls or []:
    fn = REGISTRY.get(call.function.name)
    if fn is None:
        out = {"error": "unknown function"}
    else:
        try:
            out = fn(**json.loads(call.function.arguments))
        except (TypeError, ValueError) as exc:
            out = {"error": str(exc)}
    messages.append({"role": "tool", "tool_call_id": call.id, "content": json.dumps(out)})

final = client.chat.completions.create(model="uncensored", messages=messages, tools=tools)
print(final.choices[0].message.content)

A few choices in that code are deliberate. The REGISTRY dictionary means the model can only reach functions you listed, so an invented name returns an error string and not an exception. The enum on reason narrows the legal values. The system message tells the model to use tools for facts, and the refund description says to call it only after confirmation. Descriptions are instructions, so put your business rules there.

Temperature is 0 in the first call. Argument extraction is a transcription task, not a creative one, and a deterministic setting gives you fewer surprises. Add seed if you want repeatable runs in tests.

Controlling when a function is called

The tool_choice field has three useful modes. auto lets the model answer in text or call a function. none forbids calls for that turn, which is handy for a final summary step. A named function forces exactly that call.

resp = client.chat.completions.create(
    model="uncensored",
    messages=messages,
    tools=tools,
    tool_choice={"type": "function", "function": {"name": "get_order_status"}},
)

Forcing a function is the right move for extraction tasks. If you only want structured data out of a paragraph, define one function whose parameters are the fields you need, force it, and read the arguments. You get a schema-shaped result without writing a parser. When no function is involved and the output simply must be an object, JSON mode with response_format set to json_object is lighter. Remember to tell the model in the prompt which keys you expect, because JSON mode guarantees valid JSON and does not guarantee your keys.

Validate arguments before you run them

The arguments arrive as a string and may be malformed, incomplete or plausible but wrong, such as a negative order id. Parse and validate in one step with a schema library. Pydantic does this well in Python, and Zod does the same in Node.

from pydantic import BaseModel, ValidationError
from typing import Literal

class RefundArgs(BaseModel):
    order_id: int
    reason: Literal["damaged", "late", "wrong_item", "other"]

try:
    args = RefundArgs.model_validate_json(call.function.arguments)
except ValidationError as exc:
    # send the message back as the tool result so the model can retry
    result = "invalid arguments: " + exc.errors()[0]["msg"]

Returning the validation message as the tool result gives the model a chance to repair its own call on the next turn. In practice one retry fixes most problems. Cap retries at two or three per function so a stubborn failure ends in an error for the user and not an endless loop.

Validation also protects you from the harder case: a prompt-injected argument. If a function sends email or moves money, check the target against an allowlist, require a human confirmation for anything irreversible, and log every call with its X-Request-Id header value so you can trace it later.

Several calls in one turn

A single reply can contain more than one entry in tool_calls. Ask for two currency conversions in one message and you may get two calls back. Your loop must handle a list every time, and you must answer every id, in any order, before the next request. Here is a Node version that prints them all.

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.uncensoredqwen.top/v1",
  apiKey: process.env.API_KEY,
});

const res = await client.chat.completions.create({
  model: "uncensored",
  messages: [{ role: "user", content: "Convert 250 EUR to USD and 90 GBP to USD." }],
  tools: [{
    type: "function",
    function: {
      name: "convert_currency",
      description: "Convert an amount between two ISO currency codes.",
      parameters: {
        type: "object",
        properties: {
          amount: { type: "number" },
          from: { type: "string", description: "ISO code, for example EUR" },
          to: { type: "string", description: "ISO code, for example USD" },
        },
        required: ["amount", "from", "to"],
      },
    },
  }],
});

for (const call of res.choices[0].message.tool_calls ?? []) {
  console.log(call.id, call.function.name, JSON.parse(call.function.arguments));
}

Independent calls can run in parallel with Promise.all or asyncio.gather. Keep your own parallelism below the key's limits: a full key allows 8 concurrent requests and 300 requests per minute, a trial key 2 and 60. Function execution on your side does not count, only the API requests do.

Cost of a function calling workload

Tool definitions are part of the prompt, so you pay for them on every request. Suppose five functions take about 750 tokens of schema and a support turn adds 750 tokens of conversation, so each request sends 1,500 input tokens and produces 150 output tokens. A conversation needs three requests: the first call, the second after the tool result, and a closing message.

  • Per conversation: 4,500 input tokens and 450 output tokens.
  • For 1,000 conversations: 4.5M input tokens x $0.15 = $0.675, and 0.45M output tokens x $0.50 = $0.225.
  • Total: $0.90 for 1,000 conversations.

Trimming schemas matters more than it looks, since it is the one cost that repeats. Short descriptions, no unused functions per step, and no copy-pasted examples inside parameter descriptions all help. Pricing is pay as you go from prepaid credit, with failed or refused requests not charged. See the pricing page for top-ups and bonuses.

Writing descriptions that get the right call

Most wrong calls trace back to the schema text, not to the model. Treat the description fields as the only documentation the model will ever read about your system, and edit them the way you would edit an error message.

  • Say when as well as what. "Look up the shipping status of an order by its numeric id" tells the model what the function does. Adding "Use when the customer asks where their package is" tells it when to reach for it.
  • Name the units and formats. A parameter called amount is ambiguous. "Amount in the smaller currency unit, for example cents" is not.
  • Mark what is required. List only the truly necessary fields in required. If you list everything, the model will invent values for facts the user never gave. If you list nothing, it will skip fields you need.
  • Add an escape route. Give the model a way to say it lacks information, such as a needs_clarification reply in plain text, and instruct it in the system message to ask the user instead of guessing.
  • Keep names distinct. get_order and fetch_order_details in the same list will be confused. One verb and one noun per function.

Test with a small table of user messages and the call you expect for each, including some that should produce no call at all. Run it with a fixed seed and temperature 0 after every schema change. Ten rows catch most regressions, and the whole test costs a fraction of a cent at the rates above.

Where to go from here

Get a key from the API key page; new accounts can claim $0.50 of trial credit with one click, no card needed, valid for 7 days. The docs cover the request format and the response headers. If you are comparing endpoints before you commit, the page on Qwen API options is a good companion.

Questions and answers

Is function calling the same thing as tool calling?

In the OpenAI format, yes. The request field is called tools and each tool has type function. Older code may use the deprecated functions field; use tools instead.

Can the model call a function that I did not declare?

It can produce a name that is not in your list, so look names up in a registry and return an error for unknown ones.

Why is my arguments string not valid JSON?

Models sometimes drop a quote or truncate at max_tokens. Parse inside a try block, send the error back as the tool result and let the model retry, and avoid setting max_tokens too low.

Do I need streaming for function calling?

No. Non-streaming requests return the complete tool_calls list in one response. Use streaming only when you want text to appear as it is generated.

Your key is one form away

Create an account, copy the key, change the base URL. That is the whole setup.

Get API key