SDK Reference

@bluebag/ai-sdk

Public API for the Bluebag integration with the Vercel AI SDK.

@bluebag/ai-sdk wraps the Vercel AI SDK so Bluebag can inject sessions, Skills, and tool handlers into your AI calls.

Installation

npm install @bluebag/ai-sdk

See API Keys for setting up your API key.

Exports

  • Bluebag — The main client class
  • Types: BluebagClientOptions, BluebagConfigShape, BluebagSession, BluebagErrorResponse, ToolExecutionResult

Bluebag class

The Bluebag class is the main entry point for using Bluebag with the Vercel AI SDK.

import { Bluebag } from '@bluebag/ai-sdk';
import { streamText } from 'ai';
import { anthropic } from '@ai-sdk/anthropic';

const apiKey = process.env.BLUEBAG_API_KEY;
if (!apiKey) {
  throw new Error('Missing BLUEBAG_API_KEY');
}

const bluebag = new Bluebag({
  apiKey,
  stableId: 'user-123',
  activeSkills: ['pdf-processing'],
});

const config = await bluebag.enhance({
  model: anthropic('claude-3-5-sonnet-20241022'),
  messages: [{ role: 'user', content: 'Hello from Bluebag.' }],
});

const result = streamText(config);

Constructor options

BluebagClientOptions:

OptionTypeDescription
apiKeystringYour Bluebag API key (required).
apiBaseUrlstringOverride the Bluebag API base URL.
fetchImpltypeof fetchProvide a custom fetch implementation if your runtime lacks one.
stableIdstringStable identifier for per-user session isolation.
activeSkillsstring[]Limit the session to specific Skill IDs.
stripMimeTypesstring[]Remove file parts with matching MIME types before upload.

Methods

MethodDescription
enhance(config)Enhances an AI SDK config with Bluebag tools and session.
initSession()Manually initialize a session (called automatically by enhance).
getSessionId()Get the current session ID.
setStableId(id)Set the stable ID for session isolation.
setActiveSkills(skills)Set which Skills are available for the session.

enhance() method

The enhance method initializes a Bluebag session and merges Bluebag tools into your AI SDK config.

const config = await bluebag.enhance({
  model: anthropic('claude-3-5-sonnet-20241022'),
  messages: [{ role: 'user', content: 'Analyze this file.' }],
  system: 'You are a helpful assistant.', // optional: merged with Bluebag's system prompt
  tools: { myTool: customTool }, // optional: merged with Bluebag tools
});

const result = streamText(config);

Input (BluebagConfigShape):

PropertyTypeDescription
modelLanguageModelThe AI SDK model to use.
messagesModelMessage[]Array of messages for the conversation.
systemstringOptional system prompt (merged).
toolsRecord<string, Tool>Optional tools (merged with Bluebag's).

Return value: The same config object enhanced with Bluebag session, tools, and system prompt.

Files API

bluebag.files exposes file helpers from @bluebag/core. Use them to upload files, persist artifacts, and generate download links for files created by Skills.

MethodDescription
files.createUpload a file and return metadata (includes fileId).
files.retrieveMetadataFetch metadata for a file by fileId.
files.downloadDownload the raw file as a Blob.
files.persistPersist a file beyond its default expiry.
files.mintShortLivedDownloadUrlGenerate a signed download URL for a file.
const uploaded = await bluebag.files.create({
  file: myFile,
  filename: 'report.pdf',
  mediaType: 'application/pdf',
});

const download = await bluebag.files.mintShortLivedDownloadUrl(uploaded.fileId);

Tools

Bluebag exposes the following tools to your agent:

ToolDescriptionInput Schema
bluebag_bashExecute bash commands in the sandbox{ command: string }
bluebag_code_executionRun Python, JavaScript, or TypeScript code{ language: "python" | "javascript" | "typescript", code: string, files?: Array<{fileId, path}> }
bluebag_computer_useControl the sandbox desktop{ action: "screenshot" | "click" | "type" | "key", coordinate?: [x, y], text?: string }
bluebag_text_editorView, create, and edit files{ command: "view" | "create" | "str_replace", path: string, ... }
bluebag_file_download_urlGet signed download URLs{ fileId: string, ttlSeconds?: number }

See Tool Calls for detailed input/output schemas.

Types

ToolExecutionResult<T>

type ToolExecutionResult<T> = {
  result: T;
  exitCode?: number;
  artifacts?: Array<{
    fileId: string;
    filename: string;
    path: string;
    size: number;
    expiryAt: string;
  }>;
};

BluebagSession

Re-exported from @bluebag/core. Contains session metadata.

BluebagErrorResponse

Re-exported from @bluebag/core. Error response shape from the API.

On this page