跳至正文
Wener Notes

Workers AI

约 1 分钟阅读
标签:PlatformCloudflareAIWorkers

定价

  • 免费额度: 每天 10,000 神经元 (00
    UTC 重置)
  • 付费: $0.011 / 1,000 神经元
  • 神经元 = GPU 计算单位,不同模型消耗不同

快速开始

Workers 方式

bash
# 创建项目
npm create cloudflare@latest -- hello-ai
# 选择 "Hello World example" + TypeScript

wrangler.jsonc

JSONC
{
  "ai": {
    "binding": "AI",
  },
}

src/index.ts

TypeScript
export default {
  async fetch(request, env): Promise<Response> {
    const response = await env.AI.run('@cf/meta/llama-3.1-8b-instruct', {
      prompt: 'What is the origin of the phrase Hello, World',
    });
    return Response.json(response);
  },
} satisfies ExportedHandler<Env>;
bash
npx wrangler dev    # 本地开发
npx wrangler deploy # 部署

REST API 方式

bash
# 获取 API Token 和 Account ID: https://dash.cloudflare.com/

curl https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/ai/run/@cf/meta/llama-3.1-8b-instruct \
  -H 'Authorization: Bearer {API_TOKEN}' \
  -d '{ "prompt": "Hello" }'

模型分类

类型模型示例
Text LLMLlama 3.1/3.2/4, Qwen3, Mistral, DeepSeek R1
Text-to-ImageFLUX.1, Stable Diffusion XL
Speech-to-TextWhisper, Deepgram Nova-3
Text-to-SpeechDeepgram Aura, MeloTTS
EmbeddingsBGE, EmbeddingGemma, Qwen3-Embedding
MultimodalLlama 3.2-Vision, Gemma-3
TranslationM2M100, IndicTrans2
ClassificationDistilbert, BGE-Reranker
Object DetectDETR-ResNet-50
  • 部分模型支持 LoRA 微调、批量处理、函数调用

关联信息

反向链接、本文链接的其他页面和外部资料。

参考资料

其他外链4 条
最近更新commit 906e816编辑