Examples
JorEl includes a comprehensive set of runnable examples to help you get started quickly. These examples are kept in sync with the codebase and demonstrate real-world usage patterns.
Running the Examples
All examples are located in the /examples directory of the repository. To run them:
# Clone the repository
git clone https://github.com/christianheine/jorel.git
cd jorel
# Install dependencies
npm install
# Set up your environment variables
cp .env.example .env
# Edit .env and add your API keys
# Run an example
npx ts-node examples/standard-use/open-ai/text.ts
Example Categories
Standard Use
Basic usage patterns for all supported providers:
OpenAI Examples ( examples/standard-use/open-ai/ )
text.ts- Simple text generationtext-with-metadata.ts- Getting response metadatatext-with-parameters.ts- Using generation parameterstext-with-tools.ts- Tool usage with text generationtext-with-documents.ts- Document-grounded responsestext-image.ts- Vision capabilitiestext-follow-up.ts- Follow-up conversationstext-reasoning.ts- Using reasoning models (o1, o3)text-o3.ts- o3 model specific featurestext-cancellation.ts- Cancelling requeststext-with-token-tracking.ts- NEW in v1.0.0 - Token tracking with toolsjson.ts- JSON response generationjson-schema.ts- Structured JSON with schemajson-with-tools.ts- Tools with JSON responsesstream.ts- Basic streamingstream-with-meta.ts- Streaming with metadatastream-with-tools.ts- Streaming with toolsstream-with-buffering.ts- Stream bufferingstream-reasoning.ts- Streaming with reasoning modelsstream-cancellation.ts- NEW in v1.0.0 - Cancelling streamsstream-cancellation-with-buffering.ts- NEW in v1.0.0 - Cancellation with bufferingstream-with-token-tracking.ts- NEW in v1.0.0 - Token tracking in streamsembeddings.ts- Creating embeddingsgenerate-with-tools.ts- Low-level tool usageget-client.ts- Accessing native provider clients
Other Providers
examples/standard-use/anthropic/- Anthropic (Claude) examplesexamples/standard-use/google-genai/- Google Generative AI examplesexamples/standard-use/vertex-ai/- Google Vertex AI examplesexamples/standard-use/groq/- Groq examplesexamples/standard-use/grok/- Grok examplesexamples/standard-use/mistral/- Mistral AI examplesexamples/standard-use/ollama/- Ollama (local models) examplesexamples/standard-use/open-router/- OpenRouter examples
Agent Examples
Advanced agent patterns and workflows:
Agent Examples ( examples/agents/ )
open-ai-agent--01-simple.ts- Simple single agentopen-ai-agent--02-transfer.ts- Agent transfer patternsopen-ai-agent--03-delegation.ts- Agent delegation patterns
Provider API Examples
Direct provider API usage:
Provider API Examples ( examples/provider-apis/ )
provider-apis-open-ai.ts- OpenAI provider APIprovider-apis-anthropic.ts- Anthropic provider APIprovider-apis-google-generative-ai.ts- Google Gen AI provider APIprovider-apis-advanced-with-tools.ts- Advanced provider usage with tools
Featured Examples
New in v1.0.0
Token Tracking with Tools
See how to track token usage across multiple generations when using tools:
// examples/standard-use/open-ai/text-with-token-tracking.ts
const { response, meta } = await jorEl.text(
"What's the weather in Paris and what's the stock price of AAPL?",
{ tools },
true
);
console.log(`Total input tokens: ${meta.inputTokens}`);
console.log(`Total output tokens: ${meta.outputTokens}`);
console.log(`Number of generations: ${meta.generations?.length || 1}`);
Request Cancellation
Learn how to cancel ongoing requests:
// examples/standard-use/open-ai/text-cancellation.ts
const controller = new AbortController();
const promise = jorEl.text("Write a long essay", {
abortSignal: controller.signal
});
setTimeout(() => controller.abort(), 5000);
Stream Cancellation with Buffering
Combine streaming, buffering, and cancellation:
// examples/standard-use/open-ai/stream-cancellation-with-buffering.ts
const stream = jorEl.stream("Generate a story", {
streamBuffer: { bufferTimeMs: 200 },
abortSignal: controller.signal
});
Tool Usage
Basic Tool Usage
// examples/standard-use/open-ai/text-with-tools.ts
const response = await jorEl.text("What's the weather?", {
tools: [{
name: "get_weather",
description: "Get weather for a city",
executor: getWeather,
params: z.object({ city: z.string() })
}]
});
Tool Approval Workflow
// examples/standard-use/open-ai/text-with-approval.ts
// Interactive approval of tool calls before execution
Agent Workflows
Simple Agent
// examples/agents/open-ai-agent--01-simple.ts
const agent = jorEl.team.addAgent({
name: "weather_agent",
description: "Weather specialist",
allowedTools: ["get_weather"]
});
const task = await jorEl.team.createTask("What's the weather?");
const result = await jorEl.team.executeTask(task);
Agent Delegation
// examples/agents/open-ai-agent--03-delegation.ts
// Main agent delegates subtasks to specialist agents
Vision and Images
// examples/standard-use/open-ai/text-image.ts
const image = await ImageContent.fromFile("./image.png");
const response = await jorEl.text(["What's in this image?", image]);
Reasoning Models
// examples/standard-use/open-ai/text-reasoning.ts
const response = await jorEl.text("Solve this logic puzzle", {
model: "o3-mini",
reasoningEffort: "high"
});
Utility Functions
Many examples use shared utilities located in examples/_utilities/ :
get-weather.ts- Mock weather APIget-stock-value.ts- Mock stock APIlog.ts- Console logging helpers
Browse on GitHub
Visit the examples directory on GitHub to browse all examples and see the latest additions.
Contributing Examples
If you have a useful example you'd like to share, please submit a pull request! We're always looking for real-world usage patterns to help other developers.