Cloudflare 中文文档
AI Gateway
编辑这个页面
跳转官方原文档
Set theme to dark (⇧+D)

Workers AI

Use AI Gateway for analytics, caching, and security on requests to Workers AI.

​​ REST API

To interact with a REST API, update the URL used for your request:

  • Previous: https://api.cloudflare.com/client/v4/accounts/{account_id}/ai/run/{model_id}
  • New: https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/workers-ai/{model_id}

For these parameters:

​​ Examples

First, generate an API token with Workers AI Read access and use it in your request.

​​ OpenAI compatible endpoints

Workers AI supports OpenAI compatible endpoints for text generation (/v1/chat/completions) and text embedding models (/v1/embeddings). This allows you to use the same code as you would for your OpenAI commands, but swap in Workers AI easily.

​​ Worker

To include an AI Gateway within your Worker, add the gateway as an object in your Workers AI request.

Workers AI supports the following parameters for AI gateways:

  • id string
    • Name of your existing AI Gateway. Must be in the same account as your Worker.
  • skipCache boolean(default: false)
  • cacheTtl number