SDK & Programmatic Access
Run Vesper Code agents from your own code with @vesper/sdk.
Installation
npm install @vesper/sdk
Prerequisites
API key: vespercode.com/api-keys
Quick Start
Run an agent with a few lines of code:
import { VesperCodeClient } from '@vesper/sdk'const client = new VesperCodeClient({apiKey: process.env.VESPER_API_KEY,cwd: process.cwd(),})const result = await client.run({agent: 'vesper/base@0.0.16',prompt: 'Create a simple calculator class',handleEvent: (event) => {console.log('Event:', event.type)},})
Continuing Conversations
Pass the previous run state to keep context:
const run1 = await client.run({agent: 'vesper/base@0.0.16',prompt: 'Create a calculator class',})const run2 = await client.run({agent: 'vesper/base@0.0.16',prompt: 'Add unit tests for the calculator',previousRun: run1,})
Custom Agents
import type { AgentDefinition } from '@vesper/sdk'const myAgent: AgentDefinition = {id: 'my-custom-agent',model: 'openai/gpt-5.3-codex',displayName: 'My Custom Agent',toolNames: ['read_files', 'write_file'],instructionsPrompt: 'You are a helpful coding assistant.',}await client.run({agent: 'my-custom-agent',prompt: 'Help me refactor this code',agentDefinitions: [myAgent],})
Custom Tools
import { z } from 'zod/v4'import { getCustomToolDefinition } from '@vesper/sdk'const fetchTool = getCustomToolDefinition({toolName: 'fetch_api_data',description: 'Fetch data from an API endpoint',inputSchema: z.object({url: z.url(),method: z.enum(['GET', 'POST']).default('GET'),}),execute: async ({ url, method }) => {const response = await fetch(url, { method })const data = await response.text()return [{ type: 'json', value: { data } }]},})await client.run({agent: 'my-custom-agent',prompt: 'Fetch the latest data',customToolDefinitions: [fetchTool],})
Loading Local Agents
import { loadLocalAgents, VesperCodeClient } from '@vesper/sdk'const agents = await loadLocalAgents({ verbose: true })const client = new VesperCodeClient({ apiKey: process.env.VESPER_API_KEY })await client.run({agent: 'my-local-agent',agentDefinitions: Object.values(agents),prompt: 'Hello',})
API Reference
VesperCodeClient
const client = new VesperCodeClient({apiKey: string, // Required: Your Vesper Code API keycwd?: string, // Working directory for file operations})
client.run(options)
agent(string) — Agent ID from the store or custom agent IDprompt(string) — The user promptparams(object) — Additional parameters for the agenthandleEvent(function) — Callback for streaming eventspreviousRun(RunState) — Previous run state to continue conversationprojectFiles(object) — Project files as{ path: content }knowledgeFiles(object) — Knowledge files to inject into contextagentDefinitions(array) — Custom agent definitionscustomToolDefinitions(array) — Custom tool definitionsmaxAgentSteps(number) — Maximum steps before stopping (default: ~20)
Event Types
agent_start/agent_finish— Agent lifecycletool_call/tool_result— Tool executiontext— Text responseserror— Error events
Return Value
RunState object:
sessionState— Internal state for continuing conversationsoutput— The agent's output (text, error, or structured data)
Use Cases
- CI/CD pipelines: code review, test generation, refactoring
- Batch processing
- VS Code extensions, web apps
- Automation scripts