Tutorial

How to Connect Scavio to Zhipu GLM

An r/ZaiGLM post asked how to use web_search with GLM. Wire Scavio as a tool function in 12 lines.

An r/ZaiGLM post asked: can anyone use web_search with GLM? GLM accepts the OpenAI tool-calling shape, so any HTTP search API plugs in. This tutorial wires Scavio as a tool.

Prerequisites

  • GLM API key (Zhipu)
  • Scavio API key
  • Python 3.10+

Walkthrough

Step 1: Install zhipuai

Official Python SDK.

Bash
pip install zhipuai

Step 2: Define a Scavio tool function

Plain function, returns JSON.

Python
import os, requests

def scavio_search(query: str) -> dict:
    return requests.post('https://api.scavio.dev/api/v1/search',
        headers={'x-api-key': os.environ['SCAVIO_API_KEY']},
        json={'query': query}).json()

Step 3: Register tool with GLM

OpenAI-style tools schema.

Python
tools = [{
    'type': 'function',
    'function': {
        'name': 'scavio_search',
        'description': 'Live web search — SERP results plus AI Overview citations',
        'parameters': {'type': 'object', 'properties': {'query': {'type': 'string'}}, 'required': ['query']}
    }
}]

Step 4: Call GLM with tool list

Standard chat-completion with tools.

Python
from zhipuai import ZhipuAI
client = ZhipuAI(api_key=os.environ['GLM_API_KEY'])
resp = client.chat.completions.create(
    model='glm-4-plus',
    messages=[{'role': 'user', 'content': 'best mcp practices 2026'}],
    tools=tools,
)

Step 5: Handle tool calls

If GLM returns tool_calls, run scavio_search and feed back.

Python
for tc in resp.choices[0].message.tool_calls or []:
    if tc.function.name == 'scavio_search':
        args = json.loads(tc.function.arguments)
        result = scavio_search(args['query'])
        # Feed result back as tool message and re-call GLM.

Python Example

Python
# GLM agent now has live web search. Per-call cost: $0.0043 Scavio + GLM tokens.

JavaScript Example

JavaScript
// Same shape in TS using the OpenAI SDK with GLM's base_url.

Expected Output

JSON
GLM agent responds to time-sensitive questions with grounded answers. Without the tool, GLM falls back to training-data knowledge.

Related Tutorials

Frequently Asked Questions

Most developers complete this tutorial in 15 to 30 minutes. You will need a Scavio API key (free tier works) and a working Python or JavaScript environment.

GLM API key (Zhipu). Scavio API key. Python 3.10+. A Scavio API key gives you 500 free credits per month.

Yes. The free tier includes 500 credits per month, which is more than enough to complete this tutorial and prototype a working solution.

Scavio has a native LangChain package (langchain-scavio), an MCP server, and a plain REST API that works with any HTTP client. This tutorial uses the raw REST API, but you can adapt to your framework of choice.

Start Building

An r/ZaiGLM post asked how to use web_search with GLM. Wire Scavio as a tool function in 12 lines.