Skip to main content
Runs a Workers AI chat model through Cloudflare AI Gateway’s OpenAI-compatible /compat endpoint with a tool. The OpenAI tools / tool_calls schema is forwarded as-is by the gateway; the upstream Workers AI model must support function calling. @cf/zai-org/glm-4.7-flash does.
tool_use.py

Run the Example

1

Set up your virtual environment

2

Install dependencies

3

Export environment variables

4

Run the example

Save the code above as tool_use.py, then run:
Full source: cookbook/90_models/cloudflare/tool_use.py