API Reference

turnip can be used programmatically in your Node.js projects. This reference covers the main APIs.

Installation

$ npm install turnip-agent

TurnipAgent Class

The main class for interacting with turnip programmatically:

import { TurnipAgent } from 'turnip-agent';

const agent = new TurnipAgent({
  openaiApiKey: process.env.OPENAI_API_KEY,
  heliusApiKey: process.env.HELIUS_API_KEY,
  walletPrivateKey: process.env.WALLET_PRIVATE_KEY,
});

// Generate an image
const image = await agent.generate({
  prompt: "A mystical dragon in pixel art style",
  quality: "high",
  size: "1024x1024",
  format: "png",
});

console.log(image.path);      // ./output/dragon-xxx.png
console.log(image.prompt);    // Revised prompt used

Constructor Options

openaiApiKey

*required - OpenAI API key for image generation

heliusApiKey

*required - Helius API key for Solana RPC

walletPrivateKey

*required - Base58 private key for token deployment

network

optional - Solana network: "mainnet-beta" or "devnet"

outputDir

optional - Directory for generated images (default: ./output)

Methods

generate(options)

Generate an AI image from a text prompt:

const result = await agent.generate({
  prompt: string,           // Required: Image description
  quality?: 'low' | 'medium' | 'high',  // Default: 'high'
  size?: '1024x1024' | '1536x1024' | '1024x1536',  // Default: '1024x1024'
  format?: 'png' | 'jpeg' | 'webp',  // Default: 'png'
  transparent?: boolean,    // Default: false
  stream?: boolean,         // Default: false (enable for partial images)
});

// Returns:
{
  path: string,            // Local file path
  base64: string,          // Base64-encoded image data
  prompt: string,          // Original prompt
  revisedPrompt: string,   // AI-revised prompt
  metadata: object,        // Generation metadata
}

deploy(options)

Deploy an image as a token on Solana:

const token = await agent.deploy({
  imagePath: string,        // Required: Path to image file
  name: string,             // Required: Token name
  symbol: string,           // Required: Token symbol (max 10 chars)
  description?: string,     // Token description
  twitter?: string,         // Twitter/X URL
  telegram?: string,        // Telegram URL
  website?: string,         // Website URL
  devBuyAmount?: number,    // SOL for dev buy (default: 0.1)
  slippage?: number,        // Slippage % (default: 10)
});

// Returns:
{
  mint: string,             // Token mint address
  signature: string,        // Transaction signature
  metadataUri: string,      // IPFS metadata URI
  imageUri: string,         // IPFS image URI
  pumpUrl: string,          // pump.fun URL
  solscanUrl: string,       // Solscan transaction URL
}

launch(options)

Generate and deploy in a single call:

const result = await agent.launch({
  prompt: string,           // Image generation prompt
  name: string,             // Token name
  symbol: string,           // Token symbol
  // ... all generate() and deploy() options
});

// Returns combined result from generate() and deploy()

getTokenStats(mint)

Get statistics for a deployed token:

const stats = await agent.getTokenStats('6C9WB...');

// Returns:
{
  mint: string,
  name: string,
  symbol: string,
  price: number,
  priceChange24h: number,
  marketCap: number,
  volume24h: number,
  holders: number,
  supply: number,
}

Events

Subscribe to real-time events:

// Subscribe to token events
agent.on('transaction', (tx) => {
  console.log(`${tx.type}: ${tx.amount} SOL`);
});

agent.on('newHolder', (holder) => {
  console.log(`New holder: ${holder.address}`);
});

agent.on('priceUpdate', (data) => {
  console.log(`Price: $${data.price}`);
});

// Start watching a token
await agent.watch('6C9WB...');

// Stop watching
agent.unwatch('6C9WB...');