본문으로 건너뛰기
Skillpedia
API 및 서버 (백엔드)5.4k · #14845

app-ai-binding

하는 일

이 스킬은 Cloudflare에서 실행되는 앱에 모델 기반 AI 기능을 추가하는 방법을 에이전트에게 가르칩니다. 내장 AI 바인딩이 서버 측에서 어떻게 쓰이는지, 어떤 호출에 안심하고 의존할 수 있는지 설명합니다.

사용하는 경우

  • ✓사용자가 Cloudflare의 앱에 채팅봇, 요약, 분류기를 추가하고 싶을 때.
  • ✓사용자가 Cloudflare 앱에 임베딩이나 의미 검색을 구축하고 싶은 경우.
  • ✓사용자가 Workers AI 모델로 이미지 이해나 전사를 처리하고 싶을 때.

스킬 링크

https://github.com/cloudflare/vibesdk/blob/main/worker/agents/think/skills/app-ai-binding/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/cloudflare/vibesdk/blob/main/worker/agents/think/skills/app-ai-binding/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“Cloudflare의 제 앱에 내장 AI 바인딩을 사용해 질문에 답하는 채팅봇을 추가해 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

에이전트는 서버 쪽 앱 클래스에서 선택한 모델과 입력 메시지로 AI 바인딩을 호출합니다. 브라우저는 앱 경로만 호출하므로, 모델 접근은 서버에 머뭅니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

Generated apps can call Workers AI from the App Durable Object through this.env.AI. The platform provides this binding automatically in Dynamic Worker previews and native Cloudflare deployments. Do not add an ai section to the generated app's wrangler.json.

Use only AI.run(model, inputs, options?). Preview uses a restricted proxy with this method, while deployed Workers receive the native Workers AI binding. Methods such as AI.gateway(), AI.models(), AI.autorag(), and AI.toMarkdown() are not portable between preview and deployment.

Type and usage

import { DurableObject } from "cloudflare:workers";

interface Env {
  AI: Ai;
}

export class App extends DurableObject<Env> {
  async fetch(request: Request): Promise<Response> {
    const { prompt } = await request.json<{ prompt: string }>();
    const result = await this.env.AI.run("@cf/meta/llama-4-scout-17b-16e-instruct", {
      messages: [
        { role: "system", content: "Answer clearly and concisely." },
        { role: "user", content: prompt },
      ],
    });
    return Response.json(result);
  }
}

Keep AI calls in the server-side App class. Browser code should call an app API route; it must never receive model credentials or call the binding directly.

Common tasks

Text generation

Use @cf/meta/llama-4-scout-17b-16e-instruct with either prompt or messages:

const result = await this.env.AI.run("@cf/meta/llama-4-scout-17b-16e-instruct", {
  messages: [{ role: "user", content: userPrompt }],
  max_tokens: 512,
});

Embeddings

Use @cf/baai/bge-base-en-v1.5. The response contains embedding vectors in data:

const result = await this.env.AI.run("@cf/baai/bge-base-en-v1.5", {
  text: ["first document", "second document"],
});

Image classification

Use @cf/microsoft/resnet-50 with image bytes converted to a number array:

const image = [...new Uint8Array(await request.arrayBuffer())];
const result = await this.env.AI.run("@cf/microsoft/resnet-50", { image });

Speech transcription

Use @cf/openai/whisper with audio bytes:

const audio = [...new Uint8Array(await request.arrayBuffer())];
const result = await this.env.AI.run("@cf/openai/whisper", { audio });

Model input and output shapes differ. Keep model-specific parsing close to the call and validate user input before inference. Use only active model IDs from the current Workers AI model catalog; never generate code with a deprecated model.

Limits and errors

Dynamic Worker previews enforce a per-app AI call limit. AI features must fail transparently when inference is unavailable.

  • Never return canned, random, mock, placeholder, or hard-coded content as a fallback for an AI response.
  • Never catch an AI.run() error and continue with an apparently successful response.
  • Never return 200 with fields such as fallbackUsed after inference fails.
  • Return a non-2xx JSON response containing a safe, useful error message. The frontend must display that error to the user.
  • Do not retry rate-limit failures in a loop.
try {
  const result = await this.env.AI.run("@cf/meta/llama-4-scout-17b-16e-instruct", {
    messages: [{ role: "user", content: userPrompt }],
  });
  return Response.json(result);
} catch (error) {
  const message = error instanceof Error ? error.message : "AI inference failed";
  return Response.json({ error: "AI inference failed", details: message }, { status: 503 });
}

Frontend callers must inspect both the HTTP status and error body:

const response = await fetch("./api/chat", requestOptions);
const body = await response.json<{ content?: string; error?: string; details?: string }>();
if (!response.ok) throw new Error(body.details || body.error || "AI request failed");

Use non-streaming calls for preview-compatible code. Native Workers AI deployments support { stream: true }, but streaming across the preview proxy is not guaranteed.

자주 묻는 질문

설정 파일에 AI 섹션을 추가해야 하나요?

아닙니다. 스킬은 플랫폼이 AI 바인딩을 자동으로 제공한다고 설명합니다.

브라우저가 모델을 직접 호출할 수 있나요?

아닙니다. 스킬은 브라우저 코드가 바인딩이 아니라 앱 경로를 호출해야 한다고 설명합니다.

어떤 AI 메서드를 써도 안전한가요?

스킬은 run 메서드를 쓰라고 설명합니다. 다른 AI 메서드는 미리 보기와 배포 사이에서 유지되지 않기 때문입니다.

상세 정보

작성자의 원본 설명

Build AI features in generated apps using the platform-provided Workers AI binding. Load this skill for chatbots, summarization, classification, embeddings, semantic search, image understanding, transcription, translation, or other model inference.

repo: cloudflare/vibesdk

인기도

GitHub 스타
5.4k
순위
#14845
라이선스
MIT
업데이트
2026. 10. 21.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬