pi-flare

Pi custom provider extension for Cloudflare Workers AI.

Package details

extension

Install pi-flare from npm and Pi will load the resources declared by the package manifest.

$ pi install npm:pi-flare
Package
pi-flare
Version
0.1.0
Published
Apr 24, 2026
Downloads
137/mo · 137/wk
Author
alexintosh
License
unknown
Types
extension
Size
50.4 KB
Dependencies
0 dependencies · 1 peer
Pi manifest JSON
{
  "extensions": [
    "./dist/index.js"
  ]
}

Security note

Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.

README

Pi Cloudflare Workers AI Provider

This package registers a cloudflare-workers-ai provider for pi and discovers available Cloudflare Workers AI models from your account at load time.

It uses pi's existing custom-provider system instead of building a separate agent runtime, and points pi at Cloudflare's OpenAI-compatible Workers AI endpoint:

  • Direct endpoint: https://api.cloudflare.com/client/v4/accounts/{account_id}/ai/v1
  • Optional AI Gateway endpoint: https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/workers-ai/v1

What it does

  • Discovers models from GET /accounts/{account_id}/ai/models/search
  • Optionally enriches model metadata from GET /accounts/{account_id}/ai/models/schema
  • Registers the models as a pi custom provider using api: "openai-completions"
  • Adds two helper commands:
    • /cloudflare-workers-refresh
    • /cloudflare-workers-status

Environment

Required:

  • CLOUDFLARE_ACCOUNT_ID
  • CLOUDFLARE_API_TOKEN

Optional:

  • CLOUDFLARE_AI_GATEWAY_ID
  • CLOUDFLARE_WORKERS_AI_TASK
    • Default: Text Generation
    • Use all to skip the task filter
  • CLOUDFLARE_WORKERS_AI_MODELS
    • Comma-separated allowlist of model handles
  • CLOUDFLARE_WORKERS_AI_EXCLUDE_MODELS
    • Comma-separated denylist of model handles
  • CLOUDFLARE_WORKERS_AI_MAX_MODELS
    • Positive integer limit after filtering
  • CLOUDFLARE_WORKERS_AI_SCHEMA_ENRICHMENT
    • true by default

Usage

Install from npm after publishing:

pi install npm:pi-flare

Temporary local load:

pi -e /absolute/path/to/pi-flare

Install as a project package:

pi install -l /absolute/path/to/pi-flare

After the extension loads, use /model to select a model from the cloudflare-workers-ai provider.

Development

npm install
npm run check
npm publish

Notes

  • The provider currently targets pi's openai-completions compatibility layer because it matches Cloudflare's documented OpenAI-compatible chat endpoint cleanly.
  • Model costs are currently set to 0 in pi metadata, because Cloudflare's authenticated model search API does not expose a stable per-model pricing field.