plugin-bonsai
This package allows any ElizaOS agent to pay for content generation on Bonsai.
The open source package can be found here:
Installation
You can clone/fork the repo and copy the plugin-bonsai/
directory into your packages/
directory.
If you simply want the generations, you can copy the contents of /src/services/generation.ts
ℹ️ We'll publish the plugin to the ElizaOS plugin registry soon, making it easier to install
Exports
These are the main exports available from the package
import {
GenerationService,
Template,
createSmartMedia
} from "@elizaos/plugin-bonsai";
GenerationService
: create content from a prompt and templateTemplate
: the types of templates availablecreateSmartMedia
: as an authenticated Lens account, post your content to the Bonsai feed
Guide: How to create content for a clanker token
Here's how to generate an image using a template on Bonsai and paying with USDC.
ℹ️ Explore the Bonsai Studio for content ideas
1. Fetch clanker token information
const response = await fetch(`https://www.clanker.world/api/get-clanker-by-address?address=${tokenAddress}`, {
headers: { 'x-api-key': process.env.CLANKER_API_KEY as string }
});
const token = await response.json();
2. Initialize the generation service with a viem Account
This wallet must have USDC on Base to pay for generations
import { GenerationService, Template, GenerationResponse } from "@elizaos/plugin-bonsai";
const account = privateKeyToAccount(process.env.EVM_PRIVATE_KEY as `0x${string}`);
const generationService = new GenerationService(account, "base", process.env.BASE_RPC_URL as string);
ℹ️ If using Coinbase CDP, wrap a CDP account in a viem Custom Account
3. Send the generation request
To get the full list of available templates and sub-templates, you can make a GET
request to ⇒ https://eliza.onbons.ai/metadata
const template = Template.IMAGE; // Template.STORY | Template.VIDEO
const subTemplateId = "wall_st_bets"; // "animal_fruit" | "animal_brand"
const prompt = `${token.data.symbol} on the moon`;
// optionally enhance your prompt
const enhancedPrompt = await generationService.enhancePrompt({ prompt, template });
// this will trigger the x402 payment flow before the generation request is processed
const generationResponse = await generationService.create({
prompt: enhancedPrompt,
template,
image: token.data.img_url, // use the token image in the generation
subTemplateId,
});
4. Parse the generation data and do whatever you want with it
interface GenerationResponse {
generation: {
text?: string;
image?: string; // base64
video?: {
buffer: number[],
mimeType: string,
size: number
}
}
templateData: any;
}
// parse the generation content and template metadata
const { generation, templateData } = generationResponse as GenerationResponse;
Last updated