### Install and Run Project Source: https://github.com/cloudflare/ai/blob/main/examples/tanstack-ai/README.md Install dependencies and start the development server. This is a common setup step for the project. ```bash pnpm install pnpm dev ``` -------------------------------- ### Install Dependencies and Setup Environment Source: https://github.com/cloudflare/ai/blob/main/demos/mcp-stytch-b2b-okr-manager/README.md Clone the repository, install npm dependencies, and copy environment template files. This sets up the project locally for development. ```bash git clone https://github.com/cloudflare/agents.git cd agents/demos/mcp-stytch-b2b-okr-manager npm i ``` ```bash cp .env.template .env.local cp .dev.vars.template .dev.vars ``` -------------------------------- ### Initialize and Start the MCP Server Source: https://github.com/cloudflare/ai/blob/main/demos/mcp-client/README.md Install dependencies and launch the MCP server environment. ```sh npm install npm start ``` -------------------------------- ### Initialize and Run Local Development Source: https://github.com/cloudflare/ai/blob/main/demos/remote-mcp-server/README.md Commands to clone the repository, install dependencies using pnpm, and start the development server. ```bash # clone the repository git clone https://github.com/cloudflare/ai.git # Or if using ssh: # git clone git@github.com:cloudflare/ai.git # install dependencies cd ai # Note: using pnpm instead of just "npm" pnpm install # run locally npx nx dev remote-mcp-server ``` -------------------------------- ### Initialize and run the MCP server locally Source: https://github.com/cloudflare/ai/blob/main/demos/remote-mcp-server/static/README.md Commands to clone the repository, install dependencies, and start the development server. ```bash # clone the repository git clone git@github.com:cloudflare/ai.git # install dependencies cd ai npm install # run locally npx nx dev remote-mcp-server ``` -------------------------------- ### Start Project Locally Source: https://github.com/cloudflare/ai/blob/main/demos/orchestrator-workers/README.md Use this command to start the project in development mode locally. Ensure you have Node.js and npm installed. ```bash npx nx dev orchestrator-workers ``` -------------------------------- ### Clone and run the project locally Source: https://github.com/cloudflare/ai/blob/main/demos/remote-mcp-server-descope-auth/static/README.md Commands to clone the repository, install dependencies, and start the development server. ```bash # clone the repository git clone git@github.com:cloudflare/ai.git # install dependencies cd ai npm install # run locally npx nx dev remote-mcp-server-descope-auth ``` -------------------------------- ### Start Application Source: https://github.com/cloudflare/ai/blob/main/demos/agent-task-manager/README.md Starts the application in development mode. ```bash npx nx start agent-task-manager ``` -------------------------------- ### Install Dependencies for Development Source: https://github.com/cloudflare/ai/blob/main/demos/mcp-slack-oauth/README.md Install project dependencies using npm. This command should be run before starting the development server or building the project. ```bash npm install ``` -------------------------------- ### Start Development Server Source: https://github.com/cloudflare/ai/blob/main/demos/agent-task-manager-human-in-the-loop/README.md Use this command to start the project locally. It utilizes Nx for development. ```bash npx nx dev agent-task-manager-human-in-the-loop ``` -------------------------------- ### Initialize and Run Cloudflare AI Projects Source: https://github.com/cloudflare/ai/blob/main/README.md Commands for cloning the repository, installing dependencies, running examples, and executing tests. ```bash # Clone and install git clone git@github.com:cloudflare/ai.git cd ai pnpm install # Run an example cd examples/workers-ai pnpm dev # Run tests for a package cd packages/workers-ai-provider pnpm test # Run E2E tests (requires Cloudflare credentials) pnpm test:e2e ``` -------------------------------- ### Start Local Development Server Source: https://github.com/cloudflare/ai/blob/main/demos/agent-scheduler/README.md Use this command to start the project locally for development. ```bash npx nx dev agent-scheduler ``` -------------------------------- ### Start Development Server (NPM Script) Source: https://github.com/cloudflare/ai/blob/main/demos/agent-scheduler/README.md Starts the development server using an NPM script. ```bash npx nx start agent-scheduler ``` -------------------------------- ### Clone and Install Dependencies Source: https://github.com/cloudflare/ai/blob/main/demos/mcp-stytch-consumer-todo-list/README.md Initializes the project directory and installs required Node.js packages. ```bash git clone https://github.com/cloudflare/ai.git cd ai npm i cd demos/mcp-stytch-consumer-todo-list ``` -------------------------------- ### Clone and Install Dependencies for Remote MCP Server Source: https://github.com/cloudflare/ai/blob/main/demos/mcp-server-bearer-auth/static/README.md Clone the repository and install project dependencies using npm. This is the initial setup step for local development. ```bash git clone git@github.com:cloudflare/ai.git cd ai npm install ``` -------------------------------- ### Start Development Server Source: https://github.com/cloudflare/ai/blob/main/demos/routing/README.md Initiates the local development environment using Nx and Wrangler. ```bash npx nx dev routing ``` -------------------------------- ### Copy Environment Variables Template Source: https://github.com/cloudflare/ai/blob/main/examples/tanstack-ai/README.md Copy the example environment variables file to be filled with your credentials. This is part of the setup for deploying the project. ```bash cp .dev.vars.example .dev.vars ``` -------------------------------- ### Start Local Development Server Source: https://github.com/cloudflare/ai/blob/main/demos/prompt-chaining/README.md Use this command to start the project locally for development. It utilizes Nx and the development server. ```bash npx nx dev prompt-chaining ``` -------------------------------- ### Start Project Locally Source: https://github.com/cloudflare/ai/blob/main/demos/model-scraper/README.md Command to initiate the project in a local development environment. ```bash npx nx start model-scraper ``` -------------------------------- ### Start Application in Development Mode Source: https://github.com/cloudflare/ai/blob/main/demos/orchestrator-workers/README.md Starts the application in development mode. This is similar to the 'dev' command and is useful for local testing. ```bash npx nx start orchestrator-workers ``` -------------------------------- ### Start Development Server Source: https://github.com/cloudflare/ai/blob/main/demos/tool-calling-stream-traditional/README.md Use this command to start the development server locally. It utilizes Wrangler for managing Cloudflare Workers. ```bash npx nx dev tool-calling-stream-traditional ``` -------------------------------- ### Start development server Source: https://github.com/cloudflare/ai/blob/main/demos/tool-calling-stream/README.md Run the project locally in development mode using Wrangler. ```bash npx nx dev tool-calling-stream ``` -------------------------------- ### Install Dependencies Source: https://github.com/cloudflare/ai/blob/main/demos/remote-mcp-cf-access-self-hosted/README.md Install project dependencies using npm. ```bash npm install ``` -------------------------------- ### Start Development Server (Alias) Source: https://github.com/cloudflare/ai/blob/main/demos/prompt-chaining/README.md This NPM script is an alias for the 'dev' command, starting the development server. ```bash npx nx start prompt-chaining ``` -------------------------------- ### Install Dependencies Source: https://github.com/cloudflare/ai/blob/main/packages/workers-ai-provider/README.md Install the necessary packages for the Workers AI provider and the AI SDK. ```bash npm install workers-ai-provider ai ``` -------------------------------- ### Clone Repository and Install Dependencies Source: https://github.com/cloudflare/ai/blob/main/demos/remote-mcp-server-descope-auth/README.md Clone the project repository, navigate into the directory, and install all necessary npm dependencies to set up the local development environment. ```bash # clone the repository git clone git@github.com:cloudflare/ai.git # install dependencies cd ai npm install ``` -------------------------------- ### Install AI Gateway Provider Source: https://github.com/cloudflare/ai/blob/main/packages/ai-gateway-provider/README.md Install the package via npm. ```bash npm install ai-gateway-provider ``` -------------------------------- ### Start Development Server with Wrangler Source: https://github.com/cloudflare/ai/blob/main/demos/evaluator-optimiser/README.md Starts the development server locally using Wrangler. This is useful for local testing and development. ```bash npx nx dev evaluator-optimiser ``` -------------------------------- ### AI Search Setup Source: https://github.com/cloudflare/ai/blob/main/packages/workers-ai-provider/README.md Connect your data to Cloudflare's managed RAG service for natural language querying. This example shows how to configure and use AI Search. ```APIDOC ## AI Search Setup ### Description Configure and use Cloudflare's managed RAG service, AI Search, to connect and query your data using natural language. ### Configuration (`wrangler.jsonc`) ```jsonc { "ai_search": [{ "binding": "AI_SEARCH", "name": "my-search-index" }] } ``` ### Usage (`.ts`) ```ts import { createAISearch } from "workers-ai-provider"; import { generateText } from "ai"; const aisearch = createAISearch({ binding: env.AI_SEARCH }); const { text } = await generateText({ model: aisearch(), messages: [{ role: "user", content: "How do I setup AI Gateway?" }], }); ``` **Note:** `createAutoRAG` is deprecated. Use `createAISearch` instead. ``` -------------------------------- ### Start Development Server Source: https://github.com/cloudflare/ai/blob/main/demos/ui-worker/README.md Command to initiate the local development environment for the UI Worker project. ```bash npx nx dev ui-worker ``` -------------------------------- ### Install @cloudflare/tanstack-ai Source: https://github.com/cloudflare/ai/blob/main/packages/tanstack-ai/README.md Install the core @cloudflare/tanstack-ai and @tanstack/ai packages using npm. ```bash npm install @cloudflare/tanstack-ai @tanstack/ai ``` -------------------------------- ### Install Third-Party Model Plugins Source: https://github.com/cloudflare/ai/blob/main/packages/workers-ai-provider/README.md Install optional peer dependency plugins for specific third-party model providers to enable routing through AI Gateway. ```bash npm install @ai-sdk/openai # openai, deepseek, xai/grok, groq, mistral, perplexity, cerebras, openrouter, fireworks, alibaba, minimax npm install @ai-sdk/anthropic # anthropic npm install @ai-sdk/google # google, google-vertex ``` -------------------------------- ### Start Agent Locally Source: https://github.com/cloudflare/ai/blob/main/demos/hello-world/README.md Initiates the local development server for the Agent. ```shell npm start ``` -------------------------------- ### Run Development Server Source: https://github.com/cloudflare/ai/blob/main/demos/agent-task-manager/README.md Starts the local development server for the agent task manager. ```bash npx nx dev agent-task-manager ``` -------------------------------- ### Install AI Gateway Provider SDKs Source: https://github.com/cloudflare/ai/blob/main/packages/tanstack-ai/README.md Install specific SDKs for third-party AI providers when using AI Gateway. ```bash # For OpenAI npm install @tanstack/ai-openai # For Anthropic npm install @tanstack/ai-anthropic # For Gemini npm install @tanstack/ai-gemini # For Grok npm install @tanstack/ai-grok # For OpenRouter npm install @tanstack/ai-openrouter @openrouter/sdk ``` -------------------------------- ### Start Development Server (Alias) Source: https://github.com/cloudflare/ai/blob/main/demos/evaluator-optimiser/README.md An alias for the 'dev' command, this starts the development server with Wrangler. It's a convenient shortcut for local development. ```bash npx nx start evaluator-optimiser ``` -------------------------------- ### Run Development Server Source: https://github.com/cloudflare/ai/blob/main/demos/mcp-stytch-consumer-todo-list/README.md Starts the local development environment and the MCP inspector tool. ```bash npm run dev ``` ```bash npx @modelcontextprotocol/inspector@latest ``` -------------------------------- ### POST /query API Request Example Source: https://github.com/cloudflare/ai/blob/main/demos/agent-scheduler/README.md Example cURL command to send a query to the /query endpoint for processing scheduling actions. ```bash curl -X POST \ -H "Content-Type: application/json" \ -d '{"agentId": "your-agent-id", "prompt": "your-query"}' \ http://localhost:8787/query ``` -------------------------------- ### Configure Environment Variables Source: https://github.com/cloudflare/ai/blob/main/demos/mcp-stytch-consumer-todo-list/README.md Example content for local environment files required for Stytch integration. ```text # This is what a completed .env.local file will look like VITE_STYTCH_PUBLIC_TOKEN=public-token-test-abc123-abcde-1234-0987-0000-abcd1234 VITE_STYTCH_DOMAIN=random-domain-name.customers.stytch.dev ``` ```text // This is what a completed .dev.vars file will look like STYTCH_PROJECT_ID=project-test-6c20cd16-73d5-44f7-852c-9a7e7b2ccf62 ``` -------------------------------- ### Example cURL Command for API Interaction Source: https://github.com/cloudflare/ai/blob/main/demos/tool-calling-stream-traditional/README.md This cURL command demonstrates how to send a POST request to the API endpoint to get weather information for a specified location. ```bash curl -X POST \ -H "Content-Type: application/json" \ -d '{"prompt": "What's the weather in London?"}' \ http://localhost:8787/ ``` -------------------------------- ### Start Development Server Source: https://github.com/cloudflare/ai/blob/main/demos/mcp-slack-oauth/README.md Run the development server for local testing and debugging. This command typically uses a tool like Wrangler to serve the worker locally. ```bash npm run dev ``` -------------------------------- ### Run Local Development Server Source: https://github.com/cloudflare/ai/blob/main/demos/remote-mcp-server-autorag/static/README.md Start the remote MCP server locally for development and testing. ```bash npx nx dev remote-mcp-server-autorag ``` -------------------------------- ### Configure Redirect URI Source: https://github.com/cloudflare/ai/blob/main/demos/remote-mcp-logto/README.md Example format for the production callback URL to be added to Logto. ```text https://remote-mcp-logto..workers.dev/callback ``` -------------------------------- ### Run Integration Tests for Tool Calling Source: https://github.com/cloudflare/ai/blob/main/demos/tool-calling/README.md Execute the integration tests for the tool-calling project. Ensure all dependencies are installed before running. ```bash npx nx test tool-calling ``` -------------------------------- ### API Request Body Example Source: https://github.com/cloudflare/ai/blob/main/demos/structured-output/README.md Example JSON payload for the POST request to the local development server. This body includes a prompt for content generation. ```json { "prompt": "Create a recipe for sourdough bread." } ``` -------------------------------- ### POST /confirmations/:confirmationId API Request Example Source: https://github.com/cloudflare/ai/blob/main/demos/agent-scheduler/README.md Example cURL command to confirm or reject a pending scheduling operation via the /confirmations/:confirmationId endpoint. ```bash curl -X POST \ -H "Content-Type: application/json" \ -d '{"agentId": "your-agent-id", "confirm": true}' \ http://localhost:8787/confirmations/your-confirmation-id ``` -------------------------------- ### Local Development Server Source: https://github.com/cloudflare/ai/blob/main/demos/remote-mcp-cf-access-self-hosted/README.md Start the Cloudflare Worker locally for development using Wrangler. ```bash wrangler dev ``` -------------------------------- ### Run Local MCP Server Source: https://github.com/cloudflare/ai/blob/main/demos/remote-mcp-server-autorag/README.md Start the remote MCP server locally for development and testing. ```bash npx nx dev remote-mcp-server ``` -------------------------------- ### Develop Python Worker with uv Source: https://github.com/cloudflare/ai/blob/main/demos/python-workers-mcp/README.md Use this command to start the development server for your Python Worker. ```console uv run pywrangler dev ``` -------------------------------- ### Run Local Development Server Source: https://github.com/cloudflare/ai/blob/main/demos/remote-mcp-server-descope-auth/README.md Start the local development server using the Nx CLI. This command will build and run the remote MCP server on a specified port. ```bash npx nx dev remote-mcp-server-descope-auth ``` -------------------------------- ### Interact with API via Curl Source: https://github.com/cloudflare/ai/blob/main/demos/agent-task-manager/README.md Example command to send a prompt to the task manager agent. ```bash curl -X POST \ -H "Content-Type: application/json" \ -d '{"agentId": "your-agent-id", "prompt": "your-prompt"}' \ http://localhost:8787/ ``` -------------------------------- ### Test API with curl Source: https://github.com/cloudflare/ai/blob/main/demos/remote-mcp-auth0/todos-api/README.md Verify the API by sending a GET request with an Authorization header. ```bash curl --request GET \ --url http://localhost:8788/api/me \ --header 'Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6Im...' ``` -------------------------------- ### Deploy Application with Wrangler Source: https://github.com/cloudflare/ai/blob/main/demos/evaluator-optimiser/README.md Use this command to deploy the application using Wrangler. Ensure you have Wrangler installed and configured. ```bash npx nx deploy evaluator-optimiser ``` -------------------------------- ### Configure Cursor MCP command Source: https://github.com/cloudflare/ai/blob/main/demos/remote-mcp-github-oauth/README.md Example command format for connecting Cursor to a remote MCP server. ```bash npx mcp-remote https://..workers.dev/sse ``` -------------------------------- ### Connect MCP Inspector to Local Server Source: https://github.com/cloudflare/ai/blob/main/demos/mcp-server-bearer-auth/static/README.md Start the MCP Inspector and configure it to connect to a local MCP server via SSE. Ensure the correct URL and transport type are set. ```bash npx @modelcontextprotocol/inspector ``` -------------------------------- ### Run MCP Server Locally Source: https://github.com/cloudflare/ai/blob/main/demos/remote-mcp-google-oauth/README.md Start the MCP server in local development mode. This makes the server accessible at http://localhost:8788 for testing. ```bash wrangler dev ``` -------------------------------- ### Summarization with Third-Party Providers Source: https://github.com/cloudflare/ai/blob/main/examples/tanstack-ai/README.md Examples of performing summarization tasks using third-party AI providers via the AI Gateway. The `summarize` function is used with provider-specific creation functions. ```javascript summarize() with createOpenAiSummarize ``` ```javascript summarize() with createAnthropicSummarize ``` ```javascript summarize() with createGeminiSummarize ``` -------------------------------- ### Quick Start: Use Workers AI in a Cloudflare Worker Source: https://github.com/cloudflare/ai/blob/main/packages/workers-ai-provider/README.md Example of how to create a Cloudflare Worker that uses the Workers AI provider to stream text from a model. ```typescript import { createWorkersAI } from "workers-ai-provider"; import { streamText } from "ai"; export default { async fetch(req: Request, env: { AI: Ai }) { const workersai = createWorkersAI({ binding: env.AI }); const result = streamText({ model: workersai("@cf/moonshotai/kimi-k2.7-code"), messages: [{ role: "user", content: "Write a haiku about Cloudflare" }], }); return result.toTextStreamResponse(); }, }; ``` -------------------------------- ### Build for Production Source: https://github.com/cloudflare/ai/blob/main/demos/vision/README.md Execute this command to create a production-ready build of the application. ```bash npm run build ``` -------------------------------- ### Structured Output Generation with Zod Source: https://github.com/cloudflare/ai/blob/main/packages/workers-ai-provider/README.md Generate structured output from a model using a Zod schema. This example shows how to define the expected output structure for a recipe and retrieve it. ```typescript import { generateText, Output } from "ai"; import { z } from "zod"; const { output } = await generateText({ model: workersai("@cf/moonshotai/kimi-k2.7-code"), prompt: "Recipe for spaghetti bolognese", output: Output.object({ schema: z.object({ name: z.string(), ingredients: z.array(z.object({ name: z.string(), amount: z.string() })), steps: z.array(z.string()), }), }), }); ``` -------------------------------- ### Run Remote MCP Server Locally Source: https://github.com/cloudflare/ai/blob/main/demos/mcp-server-bearer-auth/static/README.md Start the remote MCP server locally using nx. This command is used to run the development server for testing. ```bash npx nx dev remote-mcp-server-bearer-auth ``` -------------------------------- ### API Response Format Example Source: https://github.com/cloudflare/ai/blob/main/demos/structured-output/README.md Defines the expected JSON structure for the server's response. This schema outlines the format for recipe details, including name, ingredients, and steps. ```json { "recipe": { "name": "string", "ingredients": [{ "name": "string", "amount": "string" }], "steps": ["string"] } } ``` -------------------------------- ### Initialize Environment Configuration Source: https://github.com/cloudflare/ai/blob/main/demos/mcp-stytch-consumer-todo-list/README.md Copies template files to create local environment configuration files. ```bash cp .env.template .env.local ``` ```bash cp .dev.vars.template .dev.vars ``` -------------------------------- ### Configure Local Development Environment Source: https://github.com/cloudflare/ai/blob/main/demos/remote-mcp-google-oauth/README.md Set up your local development environment by creating a `.dev.vars` file with your Google OAuth client ID and secret for local testing. ```bash GOOGLE_CLIENT_ID=your_development_google_cloud_oauth_client_id GOOGLE_CLIENT_SECRET=your_development_google_cloud_oauth_client_secret ``` -------------------------------- ### Get Workflow Instance Status Source: https://github.com/cloudflare/ai/blob/main/demos/orchestrator-workers/README.md Fetches the status of an existing workflow instance by providing its ID in the URL. This is a GET request to the root endpoint with an ID parameter. ```bash curl -X GET http://localhost:8787/{id} ``` -------------------------------- ### API curl command Source: https://github.com/cloudflare/ai/blob/main/demos/tool-calling-stream/README.md Example command to interact with the API endpoint. ```bash curl -X POST \ -H "Content-Type: application/json" \ -d '{"prompt": "What is the weather in London?"}' \ http://localhost:8787/ ``` -------------------------------- ### Configure local development environment variables Source: https://github.com/cloudflare/ai/blob/main/demos/remote-mcp-server-descope-auth/static/README.md Create a .dev.vars file in the project root to store Descope credentials and the local server URL. ```bash # .dev.vars DESCOPE_PROJECT_ID="your_project_id" DESCOPE_MANAGEMENT_KEY="your_management_key" # For local development SERVER_URL="http://localhost:8787" ``` -------------------------------- ### GET /:id Source: https://github.com/cloudflare/ai/blob/main/demos/evaluator-optimiser/README.md Fetches the current status of a specific workflow instance. ```APIDOC ## GET /:id ### Description Retrieves the status and progress details of an existing workflow instance using its unique ID. ### Method GET ### Endpoint /{id} ### Parameters #### Path Parameters - **id** (string) - Required - The unique identifier of the workflow instance. ### Response #### Success Response (200) - **status** (string) - The current status of the workflow instance. ``` -------------------------------- ### Initialize AI Gateway with BYOK Source: https://github.com/cloudflare/ai/blob/main/packages/ai-gateway-provider/README.md Configure the gateway for unified billing or Bring Your Own Key scenarios. ```typescript import { createAiGateway } from "ai-gateway-provider"; import { createOpenAI } from "ai-gateway-provider/providers/openai"; import { generateText } from "ai"; const aigateway = createAiGateway({ accountId: "{CLOUDFLARE_ACCOUNT_ID}", gateway: "{GATEWAY_NAME}", apiKey: "{CF_AIG_TOKEN}", }); const openai = createOpenAI(); const { text } = await generateText({ model: aigateway(openai.chat("gpt-5.1")), prompt: "Write a vegetarian lasagna recipe for 4 people.", }); ``` -------------------------------- ### GET /models_by_capability Source: https://github.com/cloudflare/ai/blob/main/demos/model-scraper/README.md Returns models that support specific capabilities, such as tool calling. ```APIDOC ## GET /models_by_capability ### Description Returns models that support specific capabilities. ### Method GET ### Endpoint /models_by_capability ### Parameters #### Query Parameters - **capability** (string) - Required - The capability to filter models by (e.g., 'tools'). ### Response #### Success Response (200) - **models** (array) - An array of models supporting the specified capability. ``` -------------------------------- ### Configure local environment variables Source: https://github.com/cloudflare/ai/blob/main/demos/remote-mcp-auth0/todos-api/README.md Create a .dev.vars file in the project root to store Auth0 configuration. ```text AUTH0_DOMAIN=yourtenant.us.auth0.com AUTH0_AUDIENCE=urn:todos-api ``` -------------------------------- ### POST / Source: https://github.com/cloudflare/ai/blob/main/demos/agent-task-manager/README.md Interact with the task manager agent by sending a prompt to perform task-related actions. ```APIDOC ## POST / ### Description Interact with the task manager agent to perform operations such as adding, deleting, or listing tasks based on the provided prompt. ### Method POST ### Endpoint / ### Request Body - **agentId** (string) - Required - The unique identifier for the agent. - **prompt** (string) - Required - The user prompt describing the task action. ### Request Example { "agentId": "your-agent-id", "prompt": "your-prompt" } ### Response #### Success Response (200) - **message** (string) - Status message of the operation. - **task** (object) - The task object affected by the operation. - **id** (string) - Unique task identifier. - **title** (string) - Task title. - **description** (string) - Task description. - **completed** (boolean) - Completion status. - **createdAt** (number) - Timestamp of creation. #### Response Example { "message": "Task created successfully", "task": { "id": "123", "title": "Example Task", "description": "Task description", "completed": false, "createdAt": 1672531200 } } ``` -------------------------------- ### POST / Source: https://github.com/cloudflare/ai/blob/main/demos/routing/README.md Creates a new routing workflow instance to process a given prompt. ```APIDOC ## POST / ### Description Creates a new routing workflow instance to process a given prompt. ### Method POST ### Endpoint / ### Request Body - **prompt** (string) - Required - The prompt to be evaluated and processed. ### Request Example { "prompt": "Your prompt here" } ### Response #### Success Response (200) - **id** (string) - The unique identifier for the workflow instance. - **details** (string) - Status details of the workflow. #### Response Example { "id": "instance-id", "details": "status-details" } ``` -------------------------------- ### Create KV Namespace Source: https://github.com/cloudflare/ai/blob/main/demos/mcp-stytch-consumer-todo-list/README.md Initializes a new KV namespace for the application data. ```bash wrangler kv namespace create TODOS ``` -------------------------------- ### Configure Local Development Environment Variables Source: https://github.com/cloudflare/ai/blob/main/demos/remote-mcp-server-descope-auth/README.md Populate the .dev.vars file with your Descope credentials and a generated cookie encryption key. Ensure the encryption key is at least 32 bytes long. ```bash # .dev.vars DESCOPE_PROJECT_ID="your_project_id" DESCOPE_MANAGEMENT_KEY="your_management_key" COOKIE_ENCRYPTION_KEY="your_cookie_encryption_key" ``` -------------------------------- ### Run Test Suite Source: https://github.com/cloudflare/ai/blob/main/demos/agent-scheduler/README.md Executes the test suite for the application. ```bash npx nx test agent-scheduler ``` -------------------------------- ### POST / Source: https://github.com/cloudflare/ai/blob/main/demos/prompt-chaining/README.md Triggers a new workflow instance for generating technical documentation. ```APIDOC ## POST / ### Description Triggers a new workflow instance to begin the automated documentation generation process. ### Method POST ### Endpoint / ### Parameters #### Request Body - **prompt** (string) - Required - The input prompt used to initiate the documentation generation workflow. ### Request Example { "prompt": "Your prompt here" } ### Response #### Success Response (200) - **id** (string) - The unique identifier for the workflow instance. - **details** (object) - Details regarding the initialized workflow instance. #### Response Example { "id": "workflow-123", "details": { "status": "initiated" } } ``` -------------------------------- ### GET /models_by_task Source: https://github.com/cloudflare/ai/blob/main/demos/model-scraper/README.md Returns an array of models whose task.id matches the provided task parameter. ```APIDOC ## GET /models_by_task ### Description Returns an array of models whose task.id matches the provided task parameter. ### Method GET ### Endpoint /models_by_task ### Parameters #### Query Parameters - **task** (string) - Required - The task ID to filter models by. ### Response #### Success Response (200) - **models** (array) - An array of models matching the task ID. ``` -------------------------------- ### Run Test Suite Source: https://github.com/cloudflare/ai/blob/main/demos/agent-task-manager/README.md Executes the project test suite. ```bash npx nx test agent-task-manager ``` -------------------------------- ### Interact with API via cURL Source: https://github.com/cloudflare/ai/blob/main/demos/ui-worker/README.md Example request to the /api endpoint for triggering text generation tasks. ```bash curl -X POST \ http://localhost:8787/api \ -H 'Content-Type: application/json' \ -d '{"prompt": "Your task description here"}' ``` -------------------------------- ### NPM scripts for project management Source: https://github.com/cloudflare/ai/blob/main/demos/tool-calling-stream/README.md Commonly used commands for deploying, linting, testing, and type-checking the project. ```bash npx nx deploy tool-calling-stream ``` ```bash npx nx dev tool-calling-stream ``` ```bash npx nx lint tool-calling-stream ``` ```bash npx nx start tool-calling-stream ``` ```bash npx nx test tool-calling-stream ``` ```bash npx nx test:ci tool-calling-stream ``` ```bash npx nx type-check tool-calling-stream ``` -------------------------------- ### NPM Scripts for Project Management Source: https://github.com/cloudflare/ai/blob/main/demos/routing/README.md Standard commands for deploying, linting, testing, and type-checking the routing application. ```bash npx nx deploy routing ``` ```bash npx nx dev routing ``` ```bash npx nx lint routing ``` ```bash npx nx start routing ``` ```bash npx nx test routing ``` ```bash npx nx test:ci routing ``` ```bash npx nx type-check routing ``` -------------------------------- ### GET /:id - Fetch Workflow Status Source: https://github.com/cloudflare/ai/blob/main/demos/parallelisation/README.md Fetches the status of an existing workflow instance using its unique identifier. ```APIDOC ## GET /:id ### Description Fetches the status of an existing workflow instance by its ID. ### Method GET ### Endpoint /:id ### Parameters #### Path Parameters - **id** (string) - Required - The unique identifier of the workflow instance. ### Response #### Success Response (200) - **status** (string) - The current status of the workflow instance. #### Response Example ```json { "status": "processing" } ``` ``` -------------------------------- ### API Response for Workflow Status Source: https://github.com/cloudflare/ai/blob/main/demos/orchestrator-workers/README.md Example JSON response when fetching the status of a workflow instance. It provides the current status of the workflow. ```json { "status": "current-status" } ``` -------------------------------- ### Create KV Namespace Source: https://github.com/cloudflare/ai/blob/main/demos/remote-mcp-logto/README.md Command to initialize a KV namespace for storing OAuth data. ```bash npx wrangler kv namespace create "OAUTH_KV" ``` -------------------------------- ### Curl Command for Confirmation Source: https://github.com/cloudflare/ai/blob/main/demos/agent-task-manager-human-in-the-loop/README.md Example cURL command to confirm or deny an action via the /confirmations/:confirmationId endpoint. Replace placeholders. ```bash curl -X POST http://localhost:8787/confirmations/{confirmationId} -H "Content-Type: application/json" -d '{"agentId": "your-agent-id", "confirm": true}' ``` -------------------------------- ### Deploy to Cloudflare Source: https://github.com/cloudflare/ai/blob/main/demos/remote-mcp-server/README.md Commands to create a KV namespace and deploy the worker application. ```bash npx wrangler kv namespace create OAUTH_KV # Follow the guidance to add the kv namespace ID to wrangler.jsonc npm run deploy ``` -------------------------------- ### Curl Command for Task Query Source: https://github.com/cloudflare/ai/blob/main/demos/agent-task-manager-human-in-the-loop/README.md Example cURL command to send a query to the /query endpoint. Replace placeholders with actual values. ```bash curl -X POST http://localhost:8787/query -H "Content-Type: application/json" -d '{"agentId": "your-agent-id", "prompt": "your-prompt"}' ``` -------------------------------- ### Initialize AI Gateway with API Key Source: https://github.com/cloudflare/ai/blob/main/packages/ai-gateway-provider/README.md Configure the gateway using Cloudflare account credentials and an optional API key. ```typescript import { createAiGateway } from "ai-gateway-provider"; import { createOpenAI } from "ai-gateway-provider/providers/openai"; import { generateText } from "ai"; const aigateway = createAiGateway({ accountId: "{CLOUDFLARE_ACCOUNT_ID}", gateway: "{GATEWAY_NAME}", apiKey: "{CF_AIG_TOKEN}", // If your AI Gateway has authentication enabled }); const openai = createOpenAI({ apiKey: "{OPENAI_API_KEY}" }); const { text } = await generateText({ model: aigateway(openai.chat("gpt-5.1")), prompt: "Write a vegetarian lasagna recipe for 4 people.", }); ``` -------------------------------- ### Workers AI Direct Chat Source: https://github.com/cloudflare/ai/blob/main/examples/tanstack-ai/README.md Example of creating a chat interface using Workers AI directly. Requires an AI binding configured in your environment. ```javascript createWorkersAiChat(model, { binding: env.AI }) ``` -------------------------------- ### API Response for Triggering Workflow Source: https://github.com/cloudflare/ai/blob/main/demos/orchestrator-workers/README.md Example JSON response when a new workflow instance is successfully triggered. It includes an ID for tracking and status details. ```json { "id": "instance-id", "details": "status-details" } ``` -------------------------------- ### Deploy Application Source: https://github.com/cloudflare/ai/blob/main/demos/agent-task-manager/README.md Deploys the application using Wrangler. ```bash npx nx deploy agent-task-manager ``` -------------------------------- ### Run Test Suite Source: https://github.com/cloudflare/ai/blob/main/demos/tool-calling-stream-traditional/README.md Runs the project's test suite using Vitest. This is useful for verifying functionality. ```bash npx nx test tool-calling-stream-traditional ``` -------------------------------- ### Lint Python code with Ruff Source: https://github.com/cloudflare/ai/blob/main/demos/python-workers-mcp/README.md Run this command to lint your Python code using Ruff, which checks for style guide violations and potential errors. ```console uv ruff check . ``` -------------------------------- ### Create Remote MCP Server with GitHub OAuth Template Source: https://github.com/cloudflare/ai/blob/main/demos/remote-mcp-github-oauth/README.md Use this command to scaffold a new remote MCP server project pre-configured with GitHub OAuth integration. ```bash npm create cloudflare@latest -- my-mcp-server --template=cloudflare/ai/demos/remote-mcp-github-oauth ``` -------------------------------- ### Update Stytch RBAC Policy Source: https://github.com/cloudflare/ai/blob/main/demos/mcp-stytch-b2b-okr-manager/README.md Use this command to update your Stytch RBAC policy with your workspace management credentials and project ID. Replace example credentials with your own. ```bash npm run update-policy -- --key-id "workspace-key-prod-4881b817-6336-410a-a953-6eceabaf5xc9" --secret "6ZcNGH7v9Oxxxxxxxxxx" --project-id "project-test-6c20cd16-73d5-44f7-852c-9a7e7b2ccf62" ``` -------------------------------- ### Configure Local Environment Variables (.env.local) Source: https://github.com/cloudflare/ai/blob/main/demos/mcp-stytch-b2b-okr-manager/README.md Set your Stytch public token and project domain for local development. ```env VITE_STYTCH_PUBLIC_TOKEN=public-token-test-abc123-abcde-1234-0987-0000-abcd1234 VITE_STYTCH_DOMAIN=https://project-domain.customers.stytch.dev ``` -------------------------------- ### Deploy to Cloudflare Source: https://github.com/cloudflare/ai/blob/main/demos/remote-mcp-server-autorag/static/README.md Create a KV namespace, update wrangler.jsonc with the namespace ID, and deploy the worker. ```bash npx wrangler@latest kv namespace create remote-mcp-server-oauth-kv npm run deploy ``` -------------------------------- ### Image Generation with Third-Party Providers Source: https://github.com/cloudflare/ai/blob/main/examples/tanstack-ai/README.md Examples of generating images using third-party AI providers through the AI Gateway. The `generateImage` function is used with provider-specific creation functions. ```javascript generateImage() with createOpenAiImage ``` ```javascript generateImage() with createGeminiImage ``` ```javascript generateImage() with createGrokImage ``` -------------------------------- ### POST / Source: https://github.com/cloudflare/ai/blob/main/demos/tool-calling-stream/README.md Processes a user prompt and returns a streaming response from the AI model, which may involve tool execution. ```APIDOC ## POST / ### Description Processes a user prompt and returns a streaming response. The AI model identifies tasks and interacts with external tools as needed. ### Method POST ### Endpoint / ### Request Body - **prompt** (string) - Required - The user prompt to be processed by the AI model. ### Request Example { "prompt": "What is the weather in London?" } ### Response #### Success Response (200) - **response** (stream) - A streaming response containing the AI's output and tool execution results. #### Response Example { "response": "The weather in London is currently 15°C with light rain." } ``` -------------------------------- ### Third-Party Chat Provider Integration Source: https://github.com/cloudflare/ai/blob/main/examples/tanstack-ai/README.md Examples of creating chat interfaces for third-party AI providers via the AI Gateway. These functions abstract the provider-specific API calls. ```javascript createOpenAiChat ``` ```javascript createAnthropicChat ``` ```javascript createGeminiChat ``` ```javascript createGrokChat ``` -------------------------------- ### Workers AI via AI Gateway Chat Source: https://github.com/cloudflare/ai/blob/main/examples/tanstack-ai/README.md Example of creating a chat interface using Workers AI through the AI Gateway. Requires the AI Gateway ID. ```javascript createWorkersAiChat(model, { binding: env.AI.gateway(id) }) ``` -------------------------------- ### System Architecture Diagram Source: https://github.com/cloudflare/ai/blob/main/demos/agent-task-manager/README.md Mermaid diagram illustrating the flow from client to task storage. ```mermaid graph TD; A[Client] --> B[API Server]; B --> C[TaskManagerAgent]; C --> D[Task Storage]; ``` -------------------------------- ### System Diagram for Tool Calling Source: https://github.com/cloudflare/ai/blob/main/demos/tool-calling/README.md Illustrates the data flow from client to server for processing weather-related prompts and fetching data. ```mermaid graph TD; A[Client] -->|POST Request| B[DevServerTestHelper] B -->|Start Server| C[Weather Worker] C -->|Process Prompt| D[Fetch Weather Data] D -->|Return Response| A ``` -------------------------------- ### Generate Text with Workers AI Source: https://github.com/cloudflare/ai/blob/main/packages/workers-ai-provider/README.md Use the `generateText` function to get a text response from a Workers AI model. Ensure the model is correctly specified using the `workersai` helper. ```typescript import { generateText } from "ai"; const { text } = await generateText({ model: workersai("@cf/moonshotai/kimi-k2.7-code"), prompt: "Explain Workers AI in one paragraph", }); ``` -------------------------------- ### Configure Environment Variables Source: https://github.com/cloudflare/ai/blob/main/examples/tanstack-ai/README.md Fill in your Cloudflare credentials into the .dev.vars file. These variables are used for authentication and deployment. ```bash CLOUDFLARE_ACCOUNT_ID=your-cloudflare-account-id CLOUDFLARE_AI_GATEWAY_ID=your-ai-gateway-id CLOUDFLARE_API_TOKEN=your-cloudflare-api-token ``` -------------------------------- ### POST / Source: https://github.com/cloudflare/ai/blob/main/demos/evaluator-optimiser/README.md Triggers a new workflow instance for text optimization. ```APIDOC ## POST / ### Description Triggers a new workflow instance to begin the iterative drafting and optimization process. ### Method POST ### Endpoint / ### Parameters #### Request Body - **prompt** (string) - Required - The initial text prompt to be processed by the workflow. ### Request Example { "prompt": "Your prompt here" } ### Response #### Success Response (200) - **instance_id** (string) - The unique identifier for the created workflow instance. - **status** (string) - The current status of the workflow. ``` -------------------------------- ### Tool Calling with Zod Schema Source: https://github.com/cloudflare/ai/blob/main/packages/workers-ai-provider/README.md Utilize tool calling functionality with a Zod schema for defining tool inputs. This example demonstrates how to define a 'getWeather' tool and use it within the generateText function. ```typescript import { generateText, stepCountIs } from "ai"; import { z } from "zod"; const { text } = await generateText({ model: workersai("@cf/moonshotai/kimi-k2.7-code"), prompt: "What's the weather in London?", tools: { getWeather: { description: "Get the current weather for a city", inputSchema: z.object({ city: z.string() }), execute: async ({ city }) => ({ city, temperature: 18, condition: "Cloudy" }), }, }, stopWhen: stepCountIs(2), }); ``` -------------------------------- ### Configure Local Environment Variables (.dev.vars) Source: https://github.com/cloudflare/ai/blob/main/demos/mcp-stytch-b2b-okr-manager/README.md Set your Stytch project ID, secret, and domain for local development. Ensure these are kept confidential. ```env STYTCH_PROJECT_ID=project-test-6c20cd16-73d5-44f7-852c-9a7e7b2ccf62 STYTCH_PROJECT_SECRET=secret-test-..... STYTCH_DOMAIN=https://project-domain.customers.stytch.dev ``` -------------------------------- ### Chat with Reasoning Controls Source: https://github.com/cloudflare/ai/blob/main/packages/tanstack-ai/README.md Configure chat models to use reasoning capabilities like 'reasoning_effort' and 'chat_template_kwargs'. This example uses a GLM-4.7-flash model and sets reasoning effort to 'low' and disables thinking. ```typescript import { chat } from "@tanstack/ai"; import { createWorkersAiChat } from "@cloudflare/tanstack-ai"; const adapter = createWorkersAiChat("@cf/zai-org/glm-4.7-flash", { binding: env.AI, }); const response = chat({ adapter, stream: true, messages: [{ role: "user", content: "Summarize in one sentence." }], modelOptions: { // "low" | "medium" | "high" | null — null disables reasoning. reasoning_effort: "low", // Toggle thinking on models that expose template kwargs (GLM, Kimi). chat_template_kwargs: { enable_thinking: false }, }, }); ``` -------------------------------- ### Deploy to Cloudflare Source: https://github.com/cloudflare/ai/blob/main/demos/remote-mcp-server-autorag/README.md Steps to deploy the application to Cloudflare Workers, including creating a KV namespace and running the deployment command. ```bash npx wrangler kv namespace create OAUTH_KV npm run deploy ``` -------------------------------- ### Configure Claude Desktop Source: https://github.com/cloudflare/ai/blob/main/demos/remote-mcp-cf-access-self-hosted/README.md Add the self-hosted MCP server configuration to Claude Desktop's settings. ```json { "mcpServers": { "access-self-hosted": { "type": "http", "url": "https://mcp-access-self-hosted..workers.dev/mcp" } } } ``` -------------------------------- ### Configure Claude Desktop for local MCP server Source: https://github.com/cloudflare/ai/blob/main/demos/remote-mcp-server/static/README.md JSON configuration for the Claude Desktop app to connect to a local MCP server via a proxy. ```json { "mcpServers": { "math": { "command": "npx", "args": ["mcp-remote", "http://localhost:8787/sse"] } } } ```