Context
Our createJackAI() wrapper (jack-ai.ts) currently only implements .run() from the full Cloudflare Ai interface. This works for all current templates since workers-ai-provider only calls .run(), but users calling env.AI methods directly will hit missing functionality.
Current State
// What we return
{ run: (model, inputs, options?) => Promise<T | ReadableStream> }
// Full Ai interface (from @cloudflare/workers-types)
abstract class Ai {
aiGatewayLogId: string | null;
gateway(gatewayId: string): AiGateway;
autorag(autoragId: string): AutoRAG;
run(model, inputs, options?): Promise<...>;
models(params?): Promise<AiModelsSearchObject[]>;
toMarkdown(): ToMarkdownService;
toMarkdown(files, options?): Promise<ConversionResponse[]>;
}
Missing Methods
| Method |
Priority |
Notes |
gateway(id) |
P1 |
AI Gateway for caching, rate limiting, analytics. Power users need this for production |
toMarkdown() |
P2 |
Document-to-markdown conversion (PDFs, images). Useful for document processing templates |
models(params?) |
P3 |
List available models. Nice-to-have for model pickers in agent UIs |
autorag(id) |
P3 |
AutoRAG binding. Newer API, lower demand |
aiGatewayLogId |
P3 |
Only relevant once gateway() is implemented |
Implementation Approach
Each method needs a corresponding route in the binding-proxy worker (apps/binding-proxy-worker/):
/ai/gateway → forward to env.AI.gateway(id) with metering
/ai/models → forward to env.AI.models(params) with metering
/ai/toMarkdown → forward to env.AI.toMarkdown(files, options) with metering
The jack-ai.ts wrapper would add methods that call these proxy routes, same pattern as .run().
Why Not Just Use env.AI Directly?
Jack cloud is multi-tenant. The proxy provides:
- Per-project quota enforcement (1000 req/day default)
- Usage metering via Analytics Engine
- Rate limiting (100 req/10s burst protection)
Direct env.AI is not available in jack cloud deployments — only the __AI_PROXY service binding is injected.
Acceptance Criteria
Context
Our
createJackAI()wrapper (jack-ai.ts) currently only implements.run()from the full CloudflareAiinterface. This works for all current templates sinceworkers-ai-provideronly calls.run(), but users callingenv.AImethods directly will hit missing functionality.Current State
Missing Methods
gateway(id)toMarkdown()models(params?)autorag(id)aiGatewayLogIdgateway()is implementedImplementation Approach
Each method needs a corresponding route in the binding-proxy worker (
apps/binding-proxy-worker/):/ai/gateway→ forward toenv.AI.gateway(id)with metering/ai/models→ forward toenv.AI.models(params)with metering/ai/toMarkdown→ forward toenv.AI.toMarkdown(files, options)with meteringThe jack-ai.ts wrapper would add methods that call these proxy routes, same pattern as
.run().Why Not Just Use
env.AIDirectly?Jack cloud is multi-tenant. The proxy provides:
Direct
env.AIis not available in jack cloud deployments — only the__AI_PROXYservice binding is injected.Acceptance Criteria
createJackAI()return type passessatisfies Ai(or close to it).run()behavior unchangedgateway()for caching in production