Resource clients
This page covers the clients for resources the SDK manages. They are KV, object storage, AI, ISR and logging.
On this pageLook up the KV and storage clients · Call Workers AI · Use ISR and structured logging
KV
Imported from "void/kv".
kv
A typed, JSON-aware client for the inferred KV binding.
import { kv } from 'void/kv';
await kv.put('settings', { theme: 'dark' });
const settings = await kv.get<{ theme: string }>('settings');Key exports: kv, createKV(namespace), KVClient, KVMap, PutOptions, ListOptions.
kv.map(prefix) creates a typed view. Every key in it is stored under prefix:.
Storage
Imported from "void/storage".
storage
The default R2 bucket proxy for the inferred STORAGE binding.
import { storage } from 'void/storage';
await storage.put('avatars/alice.png', file);
const object = await storage.get('avatars/alice.png');Key exports: storage, createStorage(bucket).
AI
Imported from "void/ai".
ai
A typed AI client for Cloudflare AI models and native provider requests through AI Gateway.
import { ai } from 'void/ai';
const result = await ai.run('@cf/meta/llama-3.3-70b-instruct-fp8-fast', {
messages: [{ role: 'user', content: 'Summarize this release note.' }],
});
const response = await ai.provider('openai').fetch('/chat/completions', {
body: {
model: 'gpt-4o',
messages: [{ role: 'user', content: 'Summarize this release note.' }],
},
});Key exports: ai, VoidAi, provider request types. See AI for provider setup and streaming examples.
AI methods return promises. When a usage limit is hit, they reject with UsageLimit from void/limits. SDK routes and Pages actions turn uncaught limits into a structured HTTP 429. See usage limits for optional instanceof UsageLimit handling.
Provider keys
The default secret names for ai.provider(). Use apiKeyEnv to pick another name. Store each key with void secret put, never in code.
| Provider prefix | Env var |
|---|---|
openai | OPENAI_API_KEY |
anthropic | ANTHROPIC_API_KEY |
google-ai-studio | GOOGLE_API_KEY |
deepseek | DEEPSEEK_API_KEY |
groq | GROQ_API_KEY |
mistral | MISTRAL_API_KEY |
grok | GROK_API_KEY |
openrouter | OPENROUTER_API_KEY |
perplexity | PERPLEXITY_API_KEY |
cohere | COHERE_API_KEY |
cerebras | CEREBRAS_API_KEY |
huggingface | HUGGINGFACE_API_KEY |
replicate | REPLICATE_API_KEY |
baseten | BASETEN_API_KEY |
cartesia | CARTESIA_API_KEY |
deepgram | DEEPGRAM_API_KEY |
elevenlabs | ELEVENLABS_API_KEY |
fal | FAL_API_KEY |
ideogram | IDEOGRAM_API_KEY |
parallel | PARALLEL_API_KEY |
ISR
Imported from "void/isr".
revalidate(options)
Revalidates ISR-cached pages on demand. In local dev it does nothing, because there is no edge ISR cache.
import { revalidate } from 'void/isr';
await revalidate({ paths: ['/', '/blog/hello'] });
await revalidate({ all: true });Signature:
function revalidate(options: { paths?: string[]; all?: boolean }): Promise<void>;Logging
Imported from "void/log".
logger
A structured logger. It writes one JSON line per call, so you can filter deployed logs by message and fields.
import { logger } from 'void/log';
logger.info('checkout completed', { orderId, userId });
logger.error('webhook failed', { provider: 'stripe', attempt: 3 });Methods: logger.error(message, fields?), logger.warn(message, fields?), logger.info(message, fields?).