AbstractAbstractpromptSends a request to an AI model and returns the response using the Vercel AI SDK.
Supports text generation, multi-turn conversations, structured outputs, and tool calling across multiple AI providers via Cloudflare AI Gateway.
Promise resolving to the AI response with generated text and metadata
// Simple text generation
const response = await ai.prompt({
model: { speed: "fast", cost: "medium" },
prompt: "Explain quantum computing in simple terms"
});
console.log(response.text);
// Fast and cheap for simple tasks
const response = await ai.prompt({
model: { speed: "fast", cost: "low" },
prompt: "Summarize this text..."
});
console.log(response.text);
// With system instructions for complex reasoning
const response = await ai.prompt({
model: { speed: "capable", cost: "high" },
system: "You are a helpful physics tutor.",
prompt: "Explain quantum entanglement"
});
console.log(response.text);
// Multi-turn conversation
const response = await ai.prompt({
model: { speed: "balanced", cost: "medium" },
messages: [
{ role: "user", content: "What is 2+2?" },
{ role: "assistant", content: "2+2 equals 4." },
{ role: "user", content: "What about 3+3?" }
]
});
console.log(response.text);
// Structured output with Typebox schema
const response = await ai.prompt({
model: { speed: "fast", cost: "medium" },
prompt: "Extract information: John is 30 years old",
outputSchema: Type.Object({
name: Type.String(),
age: Type.Number()
})
});
console.log(response.output); // { name: "John", age: 30 }
// Tool calling
const response = await ai.prompt({
model: { speed: "balanced", cost: "medium" },
prompt: "What's the weather in San Francisco?",
tools: {
getWeather: {
description: "Get weather for a city",
parameters: Type.Object({
city: Type.String()
}),
execute: async ({ city }) => {
return { temp: 72, condition: "sunny" };
}
}
}
});
console.log(response.text); // Model's response using tool results
console.log(response.toolCalls); // Array of tool calls made
Built-in tool for prompting Large Language Models (LLMs).
The AI tool provides twists and tools with access to LLM capabilities for natural language processing, text generation, data extraction, and intelligent decision making within their workflows.
Features:
messagesoutputSchemaExample