# apifare tools for Qwen Qwen is a model, not an app, so it gets apifare through whatever runs it. Get a token first: https://apifare.com/start?origin=page:models-qwen 1. Run Qwen in an MCP client: Qwen Code (/integrations/qwen-code) is built for Qwen models and speaks MCP. 2. Or hand it apifare as tools over HTTP (Alibaba Cloud's OpenAI-compatible API): ```python import json, os, requests from openai import OpenAI llm = OpenAI( base_url="https://dashscope-us.aliyuncs.com/compatible-mode/v1", api_key=os.environ["DASHSCOPE_API_KEY"], ) APIFARE = "https://apifare.com" auth = {"authorization": "Bearer " + os.environ["APIPAY_TOKEN"]} def tool(name, description, properties): return {"type": "function", "function": { "name": name, "description": description, "parameters": {"type": "object", "properties": properties, "required": list(properties)}}} tools = [ tool("apifare_search", "Find a paid API capability by what it does", {"q": {"type": "string"}}), tool("apifare_call", "Call a capability by slug with its params", {"slug": {"type": "string"}, "params": {"type": "object"}}), ] def run(name, args): if name == "apifare_search": r = requests.get(APIFARE + "/v1/search", params={"q": args["q"]}, headers=auth) else: r = requests.post(APIFARE + "/v1/call/" + args["slug"], json=args["params"], headers=auth) return r.json() messages = [{"role": "user", "content": "Search the web for today's top AI news"}] while True: msg = llm.chat.completions.create( model="", messages=messages, tools=tools, ).choices[0].message if not msg.tool_calls: print(msg.content) break messages.append(msg) for call in msg.tool_calls: result = run(call.function.name, json.loads(call.function.arguments)) messages.append({"role": "tool", "tool_call_id": call.id, "content": json.dumps(result)}) ``` Set DASHSCOPE_API_KEY and APIPAY_TOKEN, and use a tool-calling model from https://www.alibabacloud.com/help/en/model-studio/models. Model Studio has an endpoint per region. The US one is shown; use the one for your region. 3. Caps and the kill switch are checked before dispatch; an empty balance returns HTTP 402 with a top-up link (see /errors.md). Endpoint and tool-calling format checked against https://www.alibabacloud.com/help/en/model-studio/qwen-function-calling on 2026-09-12.