Getting Started with Captain
Welcome to Captain! Choose the path that matches your use case:
Choose Your Starting Point
Option 1: SDK Integration
For developers using OpenAI SDKs or Vercel AI SDK
Captain is a drop-in replacement for OpenAI - just change the base URL and start using unlimited context:
- OpenAI SDK compatible - Use existing OpenAI code
- Multiple languages - Python, JavaScript, TypeScript support
- Unlimited context - Process millions of tokens in a single request
- No code changes - Drop-in replacement
- Real-time streaming - Familiar streaming interface
Start here if you:
- Currently use the OpenAI SDK (Python, JavaScript/TypeScript) or Vercel AI SDK
- Want the easiest migration path
- Prefer the familiar SDK interface
- Need unlimited context with minimal code changes
Option 2: HTTP API Integration
For developers making direct HTTP requests
Use Captain’s REST API directly with any HTTP client (requests, fetch, curl, etc.):
- Simple HTTP API - Standard POST requests
- Unlimited context - Process any amount of text
- No database required - Instant processing without setup
- Language agnostic - Use any programming language
Start here if you:
- Prefer direct HTTP API calls over SDKs
- Use languages without official SDK support
- Want full control over requests
- Don’t use the OpenAI SDK
Option 3: Data Lake Integration
For developers with AWS S3 or Google Cloud Storage
Index entire cloud storage buckets and query across thousands of files:
- Connect AWS S3 or GCS - Index entire buckets automatically
- Persistent databases - Query across thousands of files
- File tracking - Know which files contain what information
- Automatic updates - Re-index buckets as files change
Start here if you:
- Have documents in AWS S3 or Google Cloud Storage
- Need to query across multiple files
- Want a searchable knowledge base
- Require persistent indexed data
Get Started with Data Lake Integration →
Prerequisites
Get Your API Credentials
You’ll need:
- API Key from Captain API Studio (format:
cap_dev_...,cap_prod_...) - Organization ID (UUID format, also available in the Studio)
Store your API key securely, such as in an environment variable:
macOS / Linux
Windows
Getting Started with SDK
Captain provides OpenAI SDK compatibility. Choose your integration:
Python SDK
Perfect for developers already using the OpenAI Python SDK - Captain is a drop-in replacement.
Installation
Quick Start: Your First Request
Important: Provide context via extra_body and use system messages for instructions:
System Prompts: Custom Roles or Captain’s Default
Captain gives you full control over the AI’s persona and behavior through system prompts:
Option 1: Define Your Own Role - Use system messages to make the AI assume specific roles or behaviors:
Option 2: Use Captain’s Default - Omit the system message to use Captain’s built-in persona:
Key Points:
- System messages = AI instructions (define role, tone, behavior)
- User messages = Your actual questions or requests
extra_body.captain.context= Large documents/data to analyze- System prompts are completely optional - Captain has intelligent defaults
Streaming Responses
Get responses in real-time as they’re generated:
Processing Large Text Documents
Captain handles unlimited context automatically - no size limits:
Note: For processing PDFs, images, or other file formats, use Data Lake Integration which supports 30+ file types including PDF, DOCX, images, and more.
JavaScript/TypeScript SDK
Perfect for developers using Node.js, Deno, or Bun - Captain is a drop-in replacement for OpenAI.
Installation
Install the OpenAI SDK using npm or your preferred package manager:
Quick Start: Your First Request
Important: Provide context via experimental_providerOptions.openai.extra_body.captain.context. Create a file called example.mjs with the following code:
Execute the code with node example.mjs (or the equivalent command for Deno or Bun).
Streaming Responses
Get responses in real-time as they’re generated:
Processing Large Text Documents
Captain handles unlimited context automatically - no size limits:
Note: For processing PDFs, images, or other file formats, use Data Lake Integration which supports 30+ file types including PDF, DOCX, images, and more.
Vercel AI SDK
Perfect for developers using Vercel’s AI SDK - Captain works seamlessly with the OpenAI provider.
Installation
For tool calling, also install zod:
Quick Start: Your First Request
Important: Vercel AI SDK requires context to be passed via a custom header X-Captain-Context that must be base64-encoded (HTTP headers cannot contain newlines).
Why base64 encoding? HTTP headers cannot contain newlines or special characters, so context must be base64-encoded before being sent in the X-Captain-Context header.
Alternative: For production use, we recommend the OpenAI SDK with extra_body parameter - it’s more reliable and doesn’t require base64 encoding.
Non-Streaming Responses
For non-streaming responses, use generateText():
Tool Calling
Define tools with Vercel AI SDK’s zod schema format:
Processing Large Contexts
⚠️ Important: HTTP headers have size limits (~4-8KB). For contexts larger than ~4KB after base64 encoding:
Option 1: Use the OpenAI JavaScript SDK with extra_body (recommended)
Option 2: Use the /v1/chat/completions/upload endpoint with FormData:
For complete documentation, see Vercel AI SDK Guide.
Next Steps: SDK
- Full SDK Documentation - Complete reference for Python, JavaScript, and Vercel AI SDK
- Learn about all supported parameters
- Explore advanced streaming options
- Understand unlimited context processing
Getting Started with HTTP API
Perfect for developers making HTTP requests with any language or framework. The HTTP API provides direct access to Captain’s infinite context processing without requiring SDKs.
Authentication
All HTTP API requests require authentication via headers:
Quick Start: Your First Request
Use the /v1/responses endpoint to process text and ask questions:
Key Parameters:
input: Your context/document text (required)query: The question to ask about the context (required)stream: Set to'true'for real-time streaming (optional)
HTTP API in Different Languages
Python (requests):
JavaScript (fetch):
cURL:
Streaming Responses
Get responses in real-time as they’re generated using Server-Sent Events (SSE):
Python:
JavaScript:
cURL:
Processing Large Text Documents
Captain handles unlimited context - send text files of any size:
Note: For processing PDFs, images, or other file formats, use Data Lake Integration which supports 30+ file types.
HTTP Response Formats
Non-Streaming Response:
Streaming Response (SSE):
Error Response:
Next Steps: HTTP API
- Full HTTP API Documentation - Complete reference including
/v1/responsesendpoint - Learn about all available parameters
- Explore error handling
- Understand rate limits
Getting Started with Data Lake Integration
Perfect for indexing cloud storage buckets and querying across multiple files.
Step 1: Create a Database
Databases are containers for your indexed files. Each database is scoped to your organization and environment.
Step 2: Index Your Cloud Storage
Choose your cloud storage provider:
Option A: Index AWS S3 Bucket
Need AWS credentials? See the Cloud Credentials Guide for step-by-step instructions.
Option B: Index Google Cloud Storage Bucket
Need GCS credentials? See the Cloud Credentials Guide for step-by-step instructions.
Step 3: Monitor Indexing Progress
Step 4: Query Your Indexed Data
Query your database with AI-generated answers:
Or get raw search results (for custom RAG pipelines):
Step 5: Query with Streaming (Optional)
Get real-time responses as they’re generated:
Next Steps: Data Lake Integration
- Full Data Lake Integration Documentation - Complete reference
- Learn about database management
- Explore file-level operations
- Understand re-indexing behavior
- Monitor indexing jobs
Important Concepts
Environment Scoping
API keys are scoped to environments:
- Development (
cap_dev_*) - For testing and development - Staging (
cap_stage_*) - For pre-production testing - Production (
cap_prod_*) - For production use
Databases created with a development key can only be accessed with development keys from the same organization.
Supported File Types
Captain supports 30+ file types including:
Documents: PDF, DOCX, TXT, MD, RTF, ODT Spreadsheets: XLSX, XLS, CSV Presentations: PPTX, PPT Images: JPG, PNG (with OCR) Code: PY, JS, TS, HTML, CSS, PHP, JAVA Data: JSON, XML
See the complete file type list in the Data Lake Integration docs.
Rate Limits
Contact support@runcaptain.com to upgrade.
Comparison: SDK vs HTTP API vs Data Lake
Using the Demo Client
We provide a comprehensive demo client that showcases all Captain features:
The demo client includes examples for:
- Creating databases
- Indexing S3 and GCS buckets
- Querying indexed data
- Processing large context with Captain API
- Streaming responses
Next Steps
For SDK Users:
- Read the Full SDK Documentation
- Explore streaming and advanced features
- Learn about context handling options
- Migrate your existing OpenAI code (Python or JavaScript)
For HTTP API Users:
- Read the Full HTTP API Documentation
- Explore all available endpoints
- Learn about error handling and rate limits
- Implement in your preferred language
For Data Lake Users:
- Read the Data Lake Integration Documentation
- Get your Cloud Storage Credentials
- Index your first bucket
- Start querying your data
Additional Resources:
Getting Help
Need assistance? We’re here to help!
- Email: support@runcaptain.com
- Phone: +1 (260) CAP-TAIN
- Documentation: docs.runcaptain.com
- Status Page: status.runcaptain.com