Skip to main content
Your gateway to AI-powered intelligence. Use it for any task involving natural language understanding, content generation, or complex reasoning.

Basic Usage

Configuration Options

Required Fields

Optional Fields

Provider Selection

OpenAI (GPT Models)

Fast, high-quality models with structured outputs.
Available Models:
  • gpt-4o - Most capable, multimodal
  • gpt-4o-mini - Fast, cost-effective (recommended)
  • o1-mini - Advanced reasoning
  • gpt-4-turbo - Previous generation
Pricing (per 1M tokens):
  • gpt-4o-mini: 0.15input/0.15 input / 0.60 output
  • gpt-4o: 2.50input/2.50 input / 10.00 output

Anthropic (Claude Models)

Strong reasoning, long context, extended thinking.
Available Models:
  • claude-3-5-sonnet-20241022 - Most capable
  • claude-3-5-haiku-20241022 - Fast, cost-effective
  • claude-3-opus-20240229 - Previous generation
Pricing (per 1M tokens):
  • claude-3-5-haiku: 0.80input/0.80 input / 4.00 output
  • claude-3-5-sonnet: 3.00input/3.00 input / 15.00 output

Cloudflare Workers AI

Edge-native models with free tier.
Available Models:
  • @cf/meta/llama-3.1-8b-instruct - Fast, general purpose
  • @cf/meta/llama-3.1-70b-instruct - More capable
  • @cf/mistral/mistral-7b-instruct-v0.1 - Fast instruction following
Pricing: Free tier - 10,000 requests/day

Groq

Ultra-fast inference with LPU acceleration.
Available Models:
  • llama-3.1-8b-instant - Fastest (~200ms response)
  • llama-3.1-70b-versatile - More capable
  • mixtral-8x7b-32768 - Long context window

Machine Learning Models

For ML inference (embeddings, image classification, object detection, vision), use Workers AI models via the workers-ai provider. See: Machine Learning for complete guide including:
  • Text embeddings (7 models)
  • Image classification
  • Object detection
  • Vision models
  • Text classification

System Prompts

Basic System Prompt

Structured Output Format

Role-Based Prompts

Few-Shot Prompts

Common Patterns

Sentiment Analysis

Classification

Entity Extraction

Text Summarization

Content Generation

Question Answering (RAG)

Translation

Structured Outputs

JSON Mode (OpenAI)

JSON Schema (OpenAI Structured Outputs)

Temperature Guide

Temperature controls randomness and creativity:

Token Limits

Control output length and cost:

Input Handling

Simple String Input

Multiple Fields

Use in prompt:

Messages Array (Conversations)

For multi-turn conversations:

Advanced Techniques

Chain of Thought

Encourage step-by-step reasoning:

Self-Consistency

Run multiple times and pick most common answer:

Multi-Turn Conversations

Build context across operations:

Cost Optimization

1. Use Cheaper Models

2. Aggressive Caching

3. Lower Temperature for Cache Hits

4. Limit Token Usage

5. Use Workers AI Free Tier

6. Track AI Costs with Telemetry

Emit token usage to Analytics Engine for cost tracking and billing:
See telemetry operation for querying examples.

Performance Tips

Use Workers AI for Speed

Use Groq for Fast Inference

Parallel Operations

Run multiple AI operations in parallel:

Error Handling

Retry on Failure

Fallback Operation

Handle Rate Limits

Output Parsing

Think operations support schema-aware output mapping - when you define an output schema, the AI response is automatically mapped to your schema field names, making outputs intuitive to use in ensembles. Define your output schema and access results using your field names:
How it works:
  1. Schema defines output: { greeting: string } → AI response maps to greeting field
  2. If AI returns valid JSON, all fields are spread to top level
  3. Metadata (model, provider, tokensUsed) available via _meta

Text Output (Simple)

For simple text responses without schema:

JSON Output (Structured)

When the AI returns JSON, fields are automatically available at top level:

Output Metadata

All think operations include metadata in the _meta field:

Testing

Test AI operations with mocks:

Best Practices

1. Choose the Right Model
2. Set Appropriate Temperature
3. Use System Prompts
4. Provide Examples (Few-Shot)
5. Request Structured Output
6. Cache Expensive Operations
7. Set Token Limits
8. Handle Errors with Retry

Common Issues

Issue: Inconsistent Outputs

Solution: Lower temperature

Issue: Truncated Responses

Solution: Increase max tokens

Issue: High Costs

Solution: Use cheaper models + caching

Issue: Slow Responses

Solution: Use faster providers

Issue: Rate Limits

Solution: Add retry logic + backoff

Next Steps

code Operation

JavaScript execution

storage Operation

Data persistence

Starter Kit

Agents using think operation

Playbooks

Common agent patterns