notebooklm-kit
v2.2.0
Published
TypeScript SDK for NotebookLM API
Readme

notebooklm-kit
A TypeScript SDK for programmatic access to Google NotebookLM.
Overview
The NotebookLM Kit provides a clean, service-based interface to all NotebookLM features. Perfect for building AI research assistants, study tools, content generators, and automated knowledge management systems.
Features
Installation
npm install notebooklm-kitFrom source:
git clone https://github.com/photon-hq/notebooklm-kit.git && cd notebooklm-kit && npm run setupRequirements: Node.js >=18.0.0
Version
Current version: 2.2.0
Available Scripts
When working with the repository, you can use the following npm scripts:
| Script | Description |
|--------|-------------|
| npm install | Install dependencies and automatically build (runs postinstall) |
| npm run setup | Full setup: install dependencies, Playwright, and build |
| npm run build | Compile TypeScript to JavaScript |
| npm run build:dev | Build only (no reinstall) |
| npm run dev | Watch mode (auto-rebuild on file changes) |
| npm run clean | Remove compiled dist/ directory |
First-time setup:
npm run setupBuild only (no reinstall):
npm run build:devWatch mode (auto-rebuild):
npm run devClean build:
npm run clean && npm run buildQuick Start
1. Install the package
npm install notebooklm-kit2. Set up authentication
Auto (browser): Create .env with GOOGLE_EMAIL and GOOGLE_PASSWORD (no 2FA required)
Manual: Create .env with NOTEBOOKLM_AUTH_TOKEN and NOTEBOOKLM_COOKIES from browser DevTools (Network → Cookie header, Console → window.WIZ_global_data.SNlM0e)
3. Use the SDK
import { NotebookLMClient } from 'notebooklm-kit';
import dotenv from 'dotenv';
// Load .env file from project root (automatically detected)
dotenv.config();
async function main() {
const sdk = new NotebookLMClient({
// Credentials are automatically loaded from .env file
// Priority: NOTEBOOKLM_AUTH_TOKEN/NOTEBOOKLM_COOKIES > GOOGLE_EMAIL/GOOGLE_PASSWORD
});
try {
await sdk.connect();
// List notebooks
const notebooks = await sdk.notebooks.list();
console.log(`Found ${notebooks.length} notebooks`);
// Create a notebook
const notebook = await sdk.notebooks.create({
title: 'My Research',
emoji: '📚',
});
console.log(`Created: ${notebook.title}`);
} catch (error) {
console.error('Error:', error);
} finally {
sdk.dispose();
}
}
main();Note: The SDK automatically loads credentials from environment variables. See SDK Initialization for all configuration options.
Running Examples
The repository includes working examples in the examples/ directory. To run them:
- Set up your
.envfile in the project root (see Authentication above) - Run any example using
tsx:npx tsx examples/notebook-list.ts npx tsx examples/chat-basic.ts
Chat Example Usage:
# Interactive mode (prompts for notebook and message)
npx tsx examples/chat-basic.ts
# With notebook ID and message (streaming mode - default)
npx tsx examples/chat-basic.ts <notebook-id> "What are the key findings?"
# Non-streaming mode (get complete response at once)
npx tsx examples/chat-basic.ts <notebook-id> "What are the key findings?" --no-streamNote: The examples automatically detect and load the .env file from the project root, regardless of where you run them from.
Features
sdk.notebooks - Notebook Management
| Feature | Description | Method | Example |
|---------|-------------|--------|---------|
| List Notebooks | List all your notebooks (recently viewed) | sdk.notebooks.list() | notebook-list.ts |
| Get Notebook | Get full details of a specific notebook | sdk.notebooks.get(notebookId) | notebook-get.ts |
| Create Notebook | Create a new notebook (auto-generates title if empty) | sdk.notebooks.create(options) | notebook-create.ts |
| Update Notebook | Update notebook title or emoji | sdk.notebooks.update(notebookId, options) | notebook-update.ts |
| Delete Notebook | Delete one or more notebooks | sdk.notebooks.delete(notebookIds) | notebook-delete.ts |
| Share Notebook ⚠️ Experimental | Share notebook with users or enable link sharing | sdk.notebooks.share(notebookId, options) | notebook-share.ts |
sdk.sources - Source Management
| Feature | Description | Method | Example |
|---------|-------------|--------|---------|
| List Sources | List all sources in a notebook | sdk.sources.list(notebookId) | source-list.ts |
| Get Source | Get one or all sources | sdk.sources.get(notebookId, sourceId?) | source-get.ts |
| Add URL | Add a source from a web page URL | sdk.sources.add.url(notebookId, options) | source-add-url.ts |
| Add Text | Add a source from text content | sdk.sources.add.text(notebookId, options) | source-add-text.ts |
| Add File | Add a source from a file (PDF, image, etc.) | sdk.sources.add.file(notebookId, options) | source-add-file.ts |
| Add YouTube | Add a YouTube video as a source | sdk.sources.add.youtube(notebookId, options) | source-add-youtube.ts |
| Add Google Drive ⚠️ Experimental | Add a Google Drive file as a source | sdk.sources.add.drive(notebookId, options) | source-add-drive.ts |
| Batch Add | Add multiple sources at once | sdk.sources.add.batch(notebookId, options) | source-add-batch.ts |
| Web Search (Simple) | Search web and wait for results | sdk.sources.add.web.searchAndWait(notebookId, options) | source-web-search.ts |
| Web Search (Advanced) | Multi-step web search workflow | sdk.sources.add.web.search() → getResults() → addDiscovered() | source-web-search-advanced.ts |
| Update Source | Update source metadata | sdk.sources.update(notebookId, sourceId, updates) | source-update.ts |
| Delete Source | Delete a source from a notebook | sdk.sources.delete(notebookId, sourceId) | source-delete.ts |
| Check Status | Check source processing status | sdk.sources.status(notebookId) | source-status.ts |
sdk.artifacts - Artifact Management
| Feature | Description | Method | Example |
|---------|-------------|--------|---------|
| Create Artifact | Create study material (quiz, flashcards, mind map, etc.) | sdk.artifacts.create() or sdk.artifacts.{type}.create() | artifact-create.tsartifact-create-subservices.ts |
| List Artifacts | List all artifacts in a notebook (with filtering) | sdk.artifacts.list() | artifact-list.ts |
| Get Artifact | Get artifact details (auto-fetches content when ready) | sdk.artifacts.get() | artifact-get.ts |
| Download Artifact | Download artifact data to disk (quiz/flashcard JSON, audio file) | sdk.artifacts.download() | artifact-download.ts |
| Download Video | Download video artifact as MP4 file | sdk.artifacts.download() | artifact-video.ts |
| Download Slides | Download slide deck as PDF or PNG files | sdk.artifacts.download() | slide-download-test.ts |
| Rename Artifact | Rename an artifact | sdk.artifacts.rename() | artifact-rename.ts |
| Delete Artifact | Delete an artifact | sdk.artifacts.delete() | artifact-delete.ts |
| Share Artifact | Share artifact/notebook with users or enable link sharing | sdk.artifacts.share() | artifact-share.ts |
sdk.generation - Generation & Chat
| Feature | Description | Method | Example |
|---------|-------------|--------|---------|
| Chat (Non-streaming) | Chat with notebook content - returns complete response | sdk.generation.chat(notebookId, prompt, options?) | chat-basic.ts |
| Chat Stream | Chat with real-time streaming response chunks | sdk.generation.chatStream(notebookId, prompt, options?) | chat-basic.ts |
| Chat Conversation | Multi-turn conversations with history tracking | sdk.generation.chat(notebookId, prompt, { conversationHistory }) | chat-conversation.ts |
| Set Chat Config | Configure chat (custom prompt, learning guide, response length) | sdk.generation.setChatConfig(notebookId, config) | generation-set-chat-config.ts |
sdk.notes - Notes Management
| Feature | Description | Method | Example |
|---------|-------------|--------|---------|
| List Notes | List all notes in a notebook | sdk.notes.list(notebookId) | note-list.ts |
| Create Note | Create a new note | sdk.notes.create(notebookId, options) | note-create.ts |
| Update Note | Update a note | sdk.notes.update(notebookId, noteId, options) | note-update.ts |
| Delete Note | Delete a note | sdk.notes.delete(notebookId, noteIds) | note-delete.ts |
Core Concepts
SDK Initialization
Methods: sdk.connect() | sdk.dispose()
Basic Usage:
import { NotebookLMClient } from 'notebooklm-kit';
import dotenv from 'dotenv';
dotenv.config(); // Load .env from project root
const sdk = new NotebookLMClient({
// Credentials loaded automatically from environment variables:
// NOTEBOOKLM_AUTH_TOKEN, NOTEBOOKLM_COOKIES
// or GOOGLE_EMAIL, GOOGLE_PASSWORD
});
try {
await sdk.connect(); // Initialize SDK, authenticate, start auto-refresh
// Now you can use sdk.notebooks, sdk.sources, etc.
const notebooks = await sdk.notebooks.list();
} finally {
sdk.dispose(); // Always cleanup
}Explicit Credentials:
const sdk = new NotebookLMClient({
authToken: process.env.NOTEBOOKLM_AUTH_TOKEN!,
cookies: process.env.NOTEBOOKLM_COOKIES!,
// or
auth: {
email: process.env.GOOGLE_EMAIL!,
password: process.env.GOOGLE_PASSWORD!,
},
});
await sdk.connect();Enable Debug Mode:
Debug mode provides detailed logging for troubleshooting, API calls, authentication, and internal operations.
Option 1: Environment Variable (Recommended)
# In your .env file
NOTEBOOKLM_DEBUG=trueOption 2: Config Option
const sdk = new NotebookLMClient({
debug: true, // Enable debug logging
// ... other config
});
await sdk.connect();Option 3: Development Mode
# Automatically enables debug in development
NODE_ENV=developmentWhat Debug Mode Logs:
- ✅ RPC call details (method names, arguments, responses)
- ✅ Authentication flow (login steps, credential extraction)
- ✅ Auto-refresh operations (token refresh attempts, timing)
- ✅ Streaming responses (chunk processing, parsing)
- ✅ Error details (full stack traces, API responses)
- ✅ Response parsing (chunked data processing, validation)
Example Debug Output:
[DEBUG] RPC Call: wXbhsf with args: [null, 1, null, [2]]
[DEBUG] Response received: 200 OK
[DEBUG] Parsing chunked response: 3 chunks found
[DEBUG] Auto-refresh: Token expires in 5 minutes, refreshing now...
[DEBUG] Authentication: Extracting credentials from browser...Disable Debug:
// Explicitly disable (overrides environment variable)
const sdk = new NotebookLMClient({
debug: false,
});# Or in .env
NOTEBOOKLM_DEBUG=falseCredentials Resolution (in priority order):
- Provided in config (
authToken/cookies) - Environment variables (
NOTEBOOKLM_AUTH_TOKEN/NOTEBOOKLM_COOKIES) - Saved credentials (
credentials.jsonin project root) - reused automatically - Auto-login (if
auth.email/auth.passwordprovided) - only if no saved credentials
Note: Set
FORCE_REAUTH=truein.envto force re-authentication and ignore saved credentials- Provided in config (
Initialization:
- Creates RPC client with credentials
- Initializes all services (
notebooks,sources,artifacts, etc.) - Starts auto-refresh manager (if enabled)
Auto-Refresh:
- Begins automatically after
connect() - Runs in background, doesn't block operations
- Updates credentials and cookies automatically
- Begins automatically after
Always call dispose() when done:
- Stops auto-refresh background timers
- Prevents memory leaks
- Resets client state
- Required for graceful shutdown
try {
await sdk.connect();
// ... use SDK ...
} finally {
await sdk.dispose(); // Always cleanup
}Authentication Overview
Authentication is handled automatically when you call sdk.connect(). Credentials are resolved in this priority order:
- Provided in config (
authToken/cookies) - Environment variables (
NOTEBOOKLM_AUTH_TOKEN/NOTEBOOKLM_COOKIES) - Saved credentials (
credentials.jsonin project root) - Auto-login (if
auth.email/auth.passwordprovided)
See the Authentication section for detailed setup instructions and all configuration options.
Quota Limits
Reference: Official Documentation
Plan Types: standard (default) | plus | pro | ultra
| Limit | Standard | Plus | Pro | Ultra | |-------|----------|------|-----|-------| | Notebooks | 100/user | 200/user | 500/user | 500/user | | Sources/Notebook | 50 | 100 | 300 | 600 | | Words/Source | 500,000 | 500,000 | 500,000 | 500,000 | | File Size | 200MB | 200MB | 200MB | 200MB | | Chats/Day | 50 | 200 | 500 | 5,000 | | Audio/Video/Day | 3 | 6 | 20 | 200 | | Reports/Day | 10 | 20 | 100 | 1,000 | | Deep Research/Month | 10 | 90 | 600 | 6,000 | | Mind Maps | Unlimited | Unlimited | Unlimited | Unlimited |
- Daily quotas reset after 24 hours
- Monthly quotas reset after 30 days
- Word/File Limits: NotebookLM rejects sources >500k words or >200MB. Copy-protected PDFs cannot be imported.
- Server-Side Enforcement: Data Tables, Infographics, Slides (limits vary)
- Client-Side Validation: Optional (
enforceQuotas: true), disabled by default - Plan Selection: Set during SDK initialization:
plan: 'pro'
Authentication
Auto-Login (Recommended)
Method: Use auth config with email/password
const sdk = new NotebookLMClient({
auth: {
email: process.env.GOOGLE_EMAIL,
password: process.env.GOOGLE_PASSWORD,
headless: true, // default: true
},
});
await sdk.connect(); // Logs in, extracts auth token, prompts for cookies, saves to credentials.jsonFile Location: Create .env in your project root directory (same directory as package.json).
# .env file location: /path/to/your-project/.env
# Option 1: Auto-login with email/password (recommended - requires no 2FA)
GOOGLE_EMAIL="[email protected]"
GOOGLE_PASSWORD="your-password"
# Option 2: Manual credentials (for production or when auto-login isn't available)
NOTEBOOKLM_AUTH_TOKEN="ACi2F2NZSD7yrNvFMrCkP3vZJY1R:1766720233448"
NOTEBOOKLM_COOKIES="_ga=GA1.1.1949425436.1764104083; SID=g.a0005AiwX...; ..."
# Optional: Retry configuration
NOTEBOOKLM_MAX_RETRIES=1 # Default: 1
NOTEBOOKLM_RETRY_DELAY=1000 # Default: 1000ms
NOTEBOOKLM_RETRY_MAX_DELAY=5000 # Default: 5000ms
# Optional: Debug mode (enables detailed logging)
NOTEBOOKLM_DEBUG=true # Enable debug logging for troubleshooting
# Optional: Force re-authentication (ignore saved credentials)
FORCE_REAUTH=trueImportant:
.envfile must be in the project root (not in subdirectories)- Account must NOT have 2FA enabled (or use app-specific passwords)
- The
.envfile is automatically ignored by git (see.gitignore)
Manual Credentials
Method: Provide authToken and cookies directly
const sdk = new NotebookLMClient({
authToken: process.env.NOTEBOOKLM_AUTH_TOKEN!,
cookies: process.env.NOTEBOOKLM_COOKIES!,
enforceQuotas: true, // optional
plan: 'standard', // optional: 'standard' | 'plus' | 'pro' | 'ultra'
});
await sdk.connect();- Auth Token: Open https://notebooklm.google.com → DevTools (F12) → Console → Run:
window.WIZ_global_data.SNlM0e - Cookies: DevTools → Network tab → Any request → Headers → Copy Cookie value
Saved Credentials
Location: credentials.json in project root (e.g., notebooklm-kit/credentials.json)
When using auto-login with email/password:
- Browser opens and authenticates
- Auth token is extracted automatically
- You're prompted to manually paste cookies
- Credentials are saved to
credentials.jsonfor future use
Subsequent runs:
- Saved credentials are automatically reused (no browser prompt)
- Faster startup - no need to re-enter cookies
- Credentials file is in project root for easy viewing/editing
To force re-authentication:
- Set
FORCE_REAUTH=truein.env, or - Delete
credentials.jsonfile
Security Note: credentials.json contains sensitive authentication data. It's automatically added to .gitignore to prevent accidental commits.
Auto-Refresh Configuration
Default: Enabled with 'auto' strategy (recommended)
// Default: auto strategy (expiration-based + time-based fallback)
const sdk = new NotebookLMClient({
auth: { email: '...', password: '...' },
// autoRefresh: true (default)
});
// Time-based (simple, predictable)
autoRefresh: { strategy: 'time', interval: 10 * 60 * 1000 }
// Expiration-based (maximum efficiency)
autoRefresh: { strategy: 'expiration', refreshAhead: 5 * 60 * 1000 }
// Disable
autoRefresh: false
// Manual refresh
await sdk.refreshCredentials();- Credentials updated automatically after refresh
- Cookies kept in sync
- Runs in background, doesn't block operations
- See Auto-Refresh Strategies in Core Concepts
Quota Management
Method: sdk.getUsage() | sdk.getRemaining() | sdk.getQuotaManager()
const sdk = new NotebookLMClient({
auth: { email: '...', password: '...' },
enforceQuotas: true, // Enable client-side validation (disabled by default)
plan: 'pro', // Set plan for accurate limits
});
await sdk.connect();
// Check usage
const usage = sdk.getUsage();
const remaining = sdk.getRemaining('chats');
const limits = sdk.getQuotaManager().getLimits();- Disabled by default - enable with
enforceQuotas: true - Throws
RateLimitErrorif limit exceeded (when enabled) - Server-side enforcement always active (even if client-side disabled)
- See Quota Limits table in Core Concepts
Notebooks
Examples: notebook-list.ts | notebook-get.ts | notebook-create.ts | notebook-update.ts | notebook-delete.ts | notebook-share.ts
List Notebooks
Method: sdk.notebooks.list()
Example: notebook-list.ts
Returns: Promise<Notebook[]>
Description: Lists all your notebooks (recently viewed). Returns a lightweight array of notebooks with essential information for display/selection.
Return Fields:
projectId: string- Unique notebook ID (required for other operations)title: string- Notebook titleemoji: string- Visual identifiersourceCount: number- Number of sources in the notebook
- Automatically filters out system notebooks (e.g., "OpenStax's Biology")
- Returns only notebooks you've recently viewed
- Does not include full notebook details (use
get()for that) - Does not include sources array (use
sourcesservice for source operations) - Does not include sharing info (use
get()for sharing details)
Usage:
const notebooks = await sdk.notebooks.list()
console.log(`Found ${notebooks.length} notebooks`)
notebooks.forEach(nb => {
console.log(`${nb.emoji} ${nb.title} (${nb.sourceCount} sources)`)
})Get Notebook
Method: sdk.notebooks.get(notebookId)
Example: notebook-get.ts
Parameters:
notebookId: string- The notebook ID (required)
Returns: Promise<Notebook>
Description: Retrieves full details of a specific notebook, including analytics and sharing information. Makes parallel RPC calls to get complete notebook data.
Return Fields:
projectId: string- Unique notebook IDtitle: string- Notebook titleemoji: string- Visual identifiersourceCount?: number- Number of sources (analytics)lastAccessed?: string- Last accessed timestamp (ISO format, analytics)sharing?: SharingSettings- Sharing configuration:isShared: boolean- Whether notebook is sharedshareUrl?: string- Share URL if sharedshareId?: string- Share IDpublicAccess?: boolean- Whether public access is enabledallowedUsers?: string[]- Array of user emails with access
- Validates notebook ID format before making RPC calls
- Calls both
RPC_GET_PROJECTandRPC_GET_SHARING_DETAILSin parallel for efficiency - Sharing data is optional - won't fail if unavailable
- Does not include sources array (use
sourcesservice for source operations) lastAccessedis extracted from notebook metadata if available
Usage:
const notebook = await sdk.notebooks.get('notebook-id')
console.log(`Title: ${notebook.title}`)
console.log(`Sources: ${notebook.sourceCount || 0}`)
console.log(`Last accessed: ${notebook.lastAccessed || 'Never'}`)
if (notebook.sharing?.isShared) {
console.log(`Share URL: ${notebook.sharing.shareUrl}`)
}Create Notebook
Method: sdk.notebooks.create(options)
Example: notebook-create.ts
Parameters:
options: CreateNotebookOptionstitle: string- Notebook title (optional, auto-generated if empty)emoji?: string- Notebook emoji (optional)
Returns: Promise<Notebook>
Description: Creates a new notebook. Automatically generates a title if not provided. Validates title length before creation.
Return Fields:
projectId: string- Unique notebook ID (use this for subsequent operations)title: string- Notebook title (as provided or auto-generated)emoji: string- Default emoji
Auto-Generated Title Format:
If title is empty or not provided, generates: "Untitled Notebook {current date}"
Example: "Untitled Notebook 12/30/2024"
- Title maximum length: 100 characters
- Throws
APIErrorif title exceeds limit - Empty title is allowed (will be auto-generated)
- Quota is checked before creation (if quota manager is enabled)
- Usage is recorded after successful creation
- Returns immediately with notebook ID - no waiting required
- Does not include
sourceCount,lastAccessed, orsharing(not available for new notebooks)
Usage:
// With title
const notebook = await sdk.notebooks.create({
title: 'My Research Project',
})
// With title and emoji
const notebook = await sdk.notebooks.create({
title: 'My Research Project',
emoji: '📚',
})
// Auto-generated title
const untitled = await sdk.notebooks.create({})Update Notebook
Method: sdk.notebooks.update(notebookId, options)
Example: notebook-update.ts
Parameters:
notebookId: string- The notebook ID (required, automatically trimmed)options: UpdateNotebookOptionstitle?: string- New title (optional)emoji?: string- New emoji (optional)metadata?: Record<string, any>- Other metadata updates (optional)
Returns: Promise<Notebook> (same as get() - full notebook details)
Description:
Updates notebook title or emoji. Returns full notebook details after update (same structure as get()). Supports updating emoji only, title only, or both together.
- At least one field (
titleoremoji) must be provided - Title maximum length: 100 characters
- Notebook ID is automatically trimmed (removes trailing spaces)
- Returns error if notebook doesn't exist
Return Fields:
Same as get() - includes projectId, title, emoji, sourceCount, lastAccessed, sharing
- Notebook ID is trimmed automatically to prevent issues with trailing spaces
- Only provided fields are updated (partial updates supported)
- Returns full notebook object after update (not just updated fields)
- Does not validate notebook existence first (for performance) - returns error if not found
Usage:
// Update title only
const updated = await sdk.notebooks.update('notebook-id', {
title: 'Updated Title',
})
// Update emoji only
const updated = await sdk.notebooks.update('notebook-id', {
emoji: '🔥',
})
// Update both title and emoji
const updated = await sdk.notebooks.update('notebook-id', {
title: 'New Title',
emoji: '⭐',
})
// Update all fields
const updated = await sdk.notebooks.update('notebook-id', {
title: 'New Title',
emoji: '🎯',
})Delete Notebook
Method: sdk.notebooks.delete(notebookIds, options?)
Example: notebook-delete.ts
Parameters:
notebookIds: string | string[]- Single notebook ID or array of IDs (required)options?: DeleteNotebookOptions- Optional deletion options:mode?: 'parallel' | 'sequential'- Execution mode (default: 'parallel')
Returns: Promise<DeleteNotebookResult>
Description: Deletes one or more notebooks. For multiple notebooks, deletions are performed individually (either in parallel or sequentially) since Google's API does not support true batch deletion. Returns confirmation with deleted IDs and count.
Return Fields:
deleted: string[]- Array of successfully deleted notebook IDscount: number- Number of notebooks successfully deletedfailed?: string[]- Array of notebook IDs that failed to delete (only present if some failed)failedCount?: number- Number of notebooks that failed to delete
- All provided IDs are validated before deletion
- Throws
APIErrorif any ID is invalid - Supports both single ID and array of IDs
- Parallel (default): All notebooks are deleted simultaneously using
Promise.all(). Faster but may hit rate limits. - Sequential: Notebooks are deleted one at a time. Slower but more reliable and avoids rate limit issues.
- No confirmation required - deletion is immediate
- Google's API does not support batch deletion in a single call
- Multiple notebooks are deleted individually, one per API call
- Parallel mode is default but sequential mode is recommended for large batches to avoid rate limits
- Failed deletions are tracked separately - if some succeed and some fail, you'll get both
deletedandfailedarrays - Throws error only if ALL deletions fail (partial failures return result with
failedarray)
Usage:
// Delete single notebook
const result = await sdk.notebooks.delete('notebook-id')
console.log(`Deleted ${result.count} notebook: ${result.deleted[0]}`)
// Delete multiple notebooks (parallel - default)
const result = await sdk.notebooks.delete(['id-1', 'id-2', 'id-3'])
console.log(`Deleted ${result.count} notebooks: ${result.deleted.join(', ')}`)
// Delete multiple notebooks (sequential - recommended for large batches)
const result = await sdk.notebooks.delete(['id-1', 'id-2', 'id-3'], { mode: 'sequential' })
console.log(`Deleted ${result.count} notebooks: ${result.deleted.join(', ')}`)
if (result.failed && result.failed.length > 0) {
console.log(`Failed to delete: ${result.failed.join(', ')}`)
}Share Notebook
⚠️ Experimental: This feature is experimental and may have limitations or breaking changes in future versions.
Method: sdk.notebooks.share(notebookId, options)
Example: notebook-share.ts
Parameters:
notebookId: string- The notebook ID (required, automatically trimmed)options: ShareNotebookOptionsusers?: Array<{email: string, role: 2|3|4}>- Users to share with (optional)notify?: boolean- Notify users (default: true, only used when users are provided)accessType?: 1|2- Access type: 1=anyone with link, 2=restricted (optional, default: 2)
Returns: Promise<ShareNotebookResult>
Description: Shares notebook with users or enables link sharing. Supports multiple users with different roles. Automatically fetches updated sharing state after operation.
User Roles:
| Role | Value | Description |
|------|-------|-------------|
| Editor | 2 | Can edit notebook content |
| Viewer | 3 | Can view notebook only |
| Remove | 4 | Remove user from shared list |
Access Types:
| Access Type | Value | Description |
|-------------|-------|-------------|
| Anyone with link | 1 | Public access via share link |
| Restricted | 2 | Only specified users can access |
Return Fields:
shareUrl: string- Share URL (always present, even if not shared)success: boolean- Whether the share operation succeedednotebookId: string- The notebook ID that was sharedaccessType: 1|2- Access type: 1=anyone with link, 2=restrictedisShared: boolean- Whether the notebook is shared (true if shared with users or link enabled)users?: Array<{email: string, role: 2|3}>- Users with access (only present if users were shared)
Notify Behavior:
notifyis only used whenusersare provided- Default:
true(users are notified when permissions change) - Set to
falseto share silently - Not used when only changing link access (no user changes)
- Email addresses are validated using regex before sharing
- Throws
APIErrorif any email is invalid - Supports multiple users in a single call
Usage:
// Share with users (restricted access, notify enabled by default)
const result = await sdk.notebooks.share('notebook-id', {
users: [
{ email: '[email protected]', role: 2 }, // editor
{ email: '[email protected]', role: 3 }, // viewer
],
notify: true,
accessType: 2, // restricted
})
// Share with users (silent, no notification)
const result = await sdk.notebooks.share('notebook-id', {
users: [
{ email: '[email protected]', role: 2 },
],
notify: false,
accessType: 2,
})
// Enable link sharing (anyone with link)
const result = await sdk.notebooks.share('notebook-id', {
accessType: 1, // 1=anyone with link, 2=restricted
})
// Remove user (role: 4)
const result = await sdk.notebooks.share('notebook-id', {
users: [
{ email: '[email protected]', role: 4 }, // remove
],
accessType: 2,
})Methods
addFromURL(notebookId: string, options: AddURLSourceOptions) → Promise<string>
Add a source from a URL (web page, YouTube, etc.).
Parameters:
notebookId: string- The notebook IDoptions.url: string- URL to add
Returns:
string- Source ID
Example:
const sourceId = await sdk.sources.addFromURL('notebook-id', {
url: 'https://example.com/article',
})addFromText(notebookId: string, options: AddTextSourceOptions) → Promise<string | AddSourceResult>
Add a source from text content.
Auto-Chunking: Large texts (>500k words) are automatically split into chunks and uploaded in parallel.
Parameters:
notebookId: string- The notebook IDoptions.title: string- Source titleoptions.content: string- Text content
Returns:
string- Source ID (if not chunked)AddSourceResult- Chunk metadata (if auto-chunked)
Example:
// Small text (returns string)
const sourceId = await sdk.sources.addFromText('notebook-id', {
title: 'Research Notes',
content: 'Your text content here...',
})
// Large text (auto-chunked)
const result = await sdk.sources.addFromText('notebook-id', {
title: 'Large Document',
content: veryLongText, // > 500k words
})
if (typeof result === 'string') {
console.log(`Source ID: ${result}`)
} else {
console.log(`Uploaded ${result.chunks?.length || 0} chunks`)
}addFromFile(notebookId: string, options: AddFileSourceOptions) → Promise<string | AddSourceResult>
Add a source from a file (PDF, image, etc.).
Auto-Chunking: Large files (>200MB or >500k words) are automatically split into chunks and uploaded in parallel.
Parameters:
notebookId: string- The notebook IDoptions.content: Buffer | string- File content as Buffer or base64 stringoptions.fileName: string- File nameoptions.mimeType?: string- MIME type (e.g., 'application/pdf')
Returns:
string- Source ID (if not chunked)AddSourceResult- Chunk metadata (if auto-chunked)
Example:
import { readFile } from 'fs/promises'
// Small file (returns string)
const buffer = await readFile('./document.pdf')
const sourceId = await sdk.sources.addFromFile('notebook-id', {
content: buffer,
fileName: 'document.pdf',
mimeType: 'application/pdf',
})
// Large file (auto-chunked)
const largeBuffer = await readFile('./large-document.pdf')
const result = await sdk.sources.addFromFile('notebook-id', {
content: largeBuffer, // > 200MB or > 500k words
fileName: 'large-document.pdf',
})
if (typeof result === 'string') {
console.log(`Source ID: ${result}`)
} else {
console.log(`Uploaded ${result.chunks?.length || 0} chunks`)
}addYouTube(notebookId: string, options: AddYouTubeSourceOptions) → Promise<string>
Add a YouTube video as a source.
Parameters:
notebookId: string- The notebook IDoptions.urlOrId: string- YouTube URL or video ID
Returns:
string- Source ID
Example:
const sourceId = await sdk.sources.addYouTube('notebook-id', {
urlOrId: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
})searchWebAndWait(notebookId: string, options: SearchWebOptions) → Promise<SearchWebResult>
Search the web or Google Drive and wait for results.
Parameters:
notebookId: string- The notebook IDoptions.query: string- Search queryoptions.sourceType: SearchSourceType- WEB or GOOGLE_DRIVEoptions.mode: ResearchMode- STANDARD or DEEP
Returns:
SearchWebResult- Object with:sessionId: string- Session ID for adding sourcessources: Array<{sourceId: string, title: string, ...}>- Found sources
Example:
import { SearchSourceType, ResearchMode } from 'notebooklm-kit'
const result = await sdk.sources.searchWebAndWait('notebook-id', {
query: 'machine learning trends 2024',
sourceType: SearchSourceType.WEB,
mode: ResearchMode.STANDARD,
})
// Add selected sources
const sourceIds = await sdk.sources.addDiscovered('notebook-id', {
sessionId: result.sessionId,
sourceIds: result.sources.slice(0, 5).map(s => s.sourceId),
})pollProcessing(notebookId: string) → Promise<SourceProcessingStatus>
Check source processing status.
Parameters:
notebookId: string- The notebook ID
Returns:
SourceProcessingStatus- Object with:readyCount: number- Number of ready sourcestotalCount: number- Total sourcesprocessingCount: number- Sources being processedfailedCount: number- Failed sourcesallReady: boolean- Whether all sources are ready
Example:
const status = await sdk.sources.pollProcessing('notebook-id')
console.log(`Ready: ${status.readyCount}/${status.totalCount}`)Sources
Examples: source-list.ts | source-get.ts | source-add-url.ts | source-add-text.ts | source-add-file.ts | source-add-youtube.ts | source-add-drive.ts | source-add-batch.ts | source-web-search.ts | source-web-search-advanced.ts | source-update.ts | source-delete.ts | source-status.ts
List Sources
Method: sdk.sources.list(notebookId)
Example: source-list.ts
Parameters:
notebookId: string- The notebook ID (required)
Returns: Promise<Source[]>
Description: Retrieves a list of all sources (URLs, text, files, YouTube videos, Google Drive files, etc.) associated with a notebook. Sources are extracted from the notebook response efficiently without requiring a separate RPC call.
Return Fields:
sourceId: string- Unique identifier for the sourcetitle?: string- Source title/nametype?: SourceType- Source type (URL, TEXT, PDF, YOUTUBE_VIDEO, GOOGLE_DRIVE, IMAGE, etc.)url?: string- Source URL (for URL/YouTube sources)createdAt?: string- Creation timestamp (ISO format)updatedAt?: string- Last modified timestamp (ISO format)status?: SourceStatus- Processing status (PROCESSING,READY,FAILED)metadata?: Record<string, any>- Additional metadata (file size, MIME type, etc.)
Source Types:
URL- Web page URLTEXT- Text contentPDF- PDF fileYOUTUBE_VIDEO- YouTube videoGOOGLE_DRIVE- Google Drive fileIMAGE- Image fileVIDEO_FILE- Video file uploadPDF_FROM_DRIVE- PDF from Google DriveTEXT_NOTE- Text noteMIND_MAP_NOTE- Mind map note
- Sources are extracted from the notebook response (same RPC as
notebooks.get()) - Processing status is inferred from source metadata
- Returns empty array if notebook has no sources
- File size and MIME type are included in metadata when available
Usage:
// List all sources
const sources = await sdk.sources.list('notebook-id')
console.log(`Found ${sources.length} sources`)
// Filter by type
const pdfs = sources.filter(s => s.type === SourceType.PDF)
const urls = sources.filter(s => s.type === SourceType.URL)
// Check processing status
const ready = sources.filter(s => s.status === SourceStatus.READY)
const processing = sources.filter(s => s.status === SourceStatus.PROCESSING)Get Source
Method: sdk.sources.get(notebookId, sourceId?)
Example: source-get.ts
Parameters:
notebookId: string- The notebook ID (required)sourceId?: string- Optional source ID to get a single source
Returns: Promise<Source | Source[]> - Single source if sourceId provided, array of all sources if omitted
Description:
Get one or all sources from a notebook. If sourceId is provided, returns a single source. If omitted, returns all sources (same as list()).
Return Fields:
Same as list() - see List Sources for field descriptions.
- Returns array if
sourceIdis omitted (same aslist()) - Returns single source object if
sourceIdis provided - Throws error if source not found when
sourceIdis provided - Efficiently reuses notebook data (no separate RPC call)
Usage:
// Get all sources
const allSources = await sdk.sources.get('notebook-id')
// Get specific source
const source = await sdk.sources.get('notebook-id', 'source-id')
console.log(source.title)Add URL Source
Method: sdk.sources.add.url(notebookId, options)
Example: source-add-url.ts
Parameters:
notebookId: string- The notebook ID (required)options: AddSourceFromURLOptionsurl: string- URL to add (required)title?: string- Optional custom title
Returns: Promise<string> - Source ID
Description:
Adds a web page URL as a source. Returns immediately after source is queued. Use status() to check if source is ready.
- Returns immediately after source is queued (does not wait for processing)
- Quota is checked before adding
- Use
status()to check if source is ready - URL must be a valid HTTP/HTTPS URL
Usage:
const sourceId = await sdk.sources.add.url('notebook-id', {
url: 'https://ai.google.dev/',
title: 'Google AI Developer',
})
// Check if ready
const status = await sdk.sources.status('notebook-id')
if (!status.processing.includes(sourceId)) {
console.log('Source is ready!')
}Add Text Source
Method: sdk.sources.add.text(notebookId, options)
Example: source-add-text.ts
Parameters:
notebookId: string- The notebook ID (required)options: AddSourceFromTextOptionscontent: string- Text content (required)title: string- Source title (required)
Returns: Promise<string | AddSourceResult> - Source ID (string) if not chunked, or AddSourceResult if auto-chunked
Description: Adds text content as a source. Useful for adding notes, research summaries, or any text-based content.
Auto-Chunking:
- If text exceeds 500,000 words, it's automatically split into chunks and uploaded in parallel
- Each chunk is uploaded as a separate source (counts toward your source limit)
- Returns
AddSourceResultwith chunk count and source IDs when chunked - Small texts (≤500k words) return a simple string (backward compatible)
- Limit: 500,000 words per source
- Behavior: Large texts are automatically split into optimal chunks
- Upload: All chunks are uploaded in parallel for faster processing
- Result: Returns chunk metadata including number of chunks and all source IDs
Usage:
// Small text (returns string - backward compatible)
const sourceId = await sdk.sources.add.text('notebook-id', {
title: 'Research Notes',
content: 'Key findings from research...',
})
// Large text (auto-chunked - returns AddSourceResult)
const result = await sdk.sources.add.text('notebook-id', {
title: 'Large Document',
content: veryLongText, // > 500k words
})
if (typeof result === 'string') {
console.log(`Source ID: ${result}`)
} else {
console.log(`Uploaded ${result.chunks?.length || 0} chunks`)
console.log(`Source IDs: ${result.allSourceIds?.join(', ')}`)
}Add File Source
Method: sdk.sources.add.file(notebookId, options)
Parameters:
notebookId: string- The notebook ID (required)options: AddSourceFromFileOptionscontent: Buffer | string- File content as Buffer or base64 string (required)fileName: string- File name (required)mimeType?: string- MIME type (optional, auto-detected if not provided)
Returns: Promise<string | AddSourceResult> - Source ID (string) if not chunked, or AddSourceResult if auto-chunked
Description: Adds a file (PDF, image, video, etc.) as a source. Supports files as Buffer or base64 string.
Auto-Chunking:
- Files exceeding 200MB or containing more than 500,000 words are automatically split into chunks
- Text-based files (txt, md, csv, json, etc.): Chunked by word count (500k words per chunk)
- Binary files: Chunked by size (200MB per chunk)
- All chunks are uploaded in parallel for faster processing
- Each chunk counts as a separate source toward your source limit
- Small files return a simple string (backward compatible)
- Size Limit: 200MB per source
- Word Limit: 500,000 words per source
- Text Files: Automatically extracted and chunked by word count
- Binary Files: Chunked by file size
- PDFs: Chunked by size (text extraction requires a PDF library)
- Result: Returns chunk metadata including number of chunks and all source IDs
Supported File Types:
- PDF files
- Image files (PNG, JPG, etc.)
- Video files
- Text files (txt, md, csv, json, etc.)
- Other document types
Usage:
import fs from 'fs'
// Small file (returns string - backward compatible)
const fileBuffer = fs.readFileSync('document.pdf')
const sourceId = await sdk.sources.add.file('notebook-id', {
content: fileBuffer,
fileName: 'document.pdf',
mimeType: 'application/pdf',
})
// Large file (auto-chunked - returns AddSourceResult)
const largeFileBuffer = fs.readFileSync('large-document.pdf')
const result = await sdk.sources.add.file('notebook-id', {
content: largeFileBuffer, // > 200MB or > 500k words
fileName: 'large-document.pdf',
})
if (typeof result === 'string') {
console.log(`Source ID: ${result}`)
} else {
console.log(`Uploaded ${result.chunks?.length || 0} chunks`)
console.log(`Source IDs: ${result.allSourceIds?.join(', ')}`)
}Add YouTube Source
Method: sdk.sources.add.youtube(notebookId, options)
Example: source-add-youtube.ts
Parameters:
notebookId: string- The notebook ID (required)options: AddYouTubeSourceOptionsurlOrId: string- YouTube URL or video ID (required)title?: string- Optional custom title
Returns: Promise<string> - Source ID
Description: Adds a YouTube video as a source. Accepts either full YouTube URL or just the video ID.
Usage:
// From YouTube URL
const sourceId = await sdk.sources.add.youtube('notebook-id', {
urlOrId: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
})
// From video ID
const sourceId = await sdk.sources.add.youtube('notebook-id', {
urlOrId: 'dQw4w9WgXcQ',
})Add Google Drive Source
⚠️ Experimental: This feature is experimental and may have limitations or breaking changes in future versions.
Method: sdk.sources.add.drive(notebookId, options)
Parameters:
notebookId: string- The notebook ID (required)options: AddGoogleDriveSourceOptionsfileId: string- Google Drive file ID (required)title?: string- Optional custom titlemimeType?: string- MIME type (optional, inferred if not provided)
Returns: Promise<string> - Source ID
Description: Adds a Google Drive file as a source. Requires the file ID from Google Drive.
This method is deprecated. Use add.batch() with type: 'gdrive' instead.
Usage:
const sourceId = await sdk.sources.add.drive('notebook-id', {
fileId: '1a2b3c4d5e6f7g8h9i0j',
mimeType: 'application/vnd.google-apps.document',
title: 'My Document',
})Batch Add Sources
Method: sdk.sources.add.batch(notebookId, options)
Example: source-add-batch.ts
Parameters:
notebookId: string- The notebook ID (required)options: BatchAddSourcesOptionssources: Array<...>- Array of source inputs (required)waitForProcessing?: boolean- Whether to wait for all sources to be processed (default: false)timeout?: number- Timeout in ms ifwaitForProcessingis true (default: 300000 = 5 minutes)pollInterval?: number- Poll interval in ms (default: 2000 = 2 seconds)onProgress?: (ready: number, total: number) => void- Progress callback
Returns: Promise<string[]> - Array of source IDs
Description: Adds multiple sources at once. Supports mixed source types (URLs, text, files, YouTube, Google Drive) in a single call.
Source Types:
{ type: 'url', url: string, title?: string }- URL source{ type: 'text', title: string, content: string }- Text source{ type: 'file', content: Buffer | string, fileName: string, mimeType?: string }- File source{ type: 'youtube', urlOrId: string, title?: string }- YouTube source{ type: 'gdrive', fileId: string, title?: string, mimeType?: string }- Google Drive source ⚠️ Experimental
Usage:
const sourceIds = await sdk.sources.add.batch('notebook-id', {
sources: [
{ type: 'url', url: 'https://example.com', title: 'Example' },
{ type: 'text', title: 'Notes', content: 'Content here...' },
{ type: 'youtube', urlOrId: 'dQw4w9WgXcQ' },
],
waitForProcessing: true, // Optional: wait for all to be ready
timeout: 300000, // 5 minutes
onProgress: (ready, total) => {
console.log(`Progress: ${ready}/${total}`)
},
})Web Search (Simple)
Method: sdk.sources.add.web.searchAndWait(notebookId, options)
Example: source-web-search.ts
Parameters:
notebookId: string- The notebook ID (required)options: SearchWebAndWaitOptionsquery: string- Search query (required)sourceType?: SearchSourceType- Source type:WEB(default) orGOOGLE_DRIVEmode?: ResearchMode- Research mode:FAST(default) orDEEP(web only)timeout?: number- Max wait time in ms (default: 60000 = 60 seconds)pollInterval?: number- Poll interval in ms (default: 2000 = 2 seconds)onProgress?: (status) => void- Progress callback
Returns: Promise<WebSearchResult> - Results with sessionId, web sources, and drive sources
Description: RECOMMENDED FOR SIMPLE WORKFLOWS - One call that searches and waits for results automatically. Returns all discovered sources once available (or timeout). Perfect for automated workflows where you don't need to see intermediate steps.
Research Modes:
ResearchMode.FAST- Quick search (~10-30 seconds, default)ResearchMode.DEEP- Comprehensive research (~60-120 seconds, web only)
Source Types:
SearchSourceType.WEB- Search web (default)SearchSourceType.GOOGLE_DRIVE- Search Google Drive (FAST mode only) ⚠️ Experimental
Return Fields:
sessionId: string- Required for adding sources (use withaddDiscovered())web: DiscoveredWebSource[]- Discovered web sourcesdrive: DiscoveredDriveSource[]- Discovered Google Drive sources ⚠️ Experimental
- Automatically polls for results until available or timeout
- Returns results once count stabilizes (assumes search complete)
- Progress callback shows result count as search progresses
- Use returned
sessionIdwithaddDiscovered()to add selected sources
Usage:
import { ResearchMode, SearchSourceType } from 'notebooklm-kit'
// Simple search and wait
const result = await sdk.sources.add.web.searchAndWait('notebook-id', {
query: 'machine learning research papers 2024',
mode: ResearchMode.DEEP, // Comprehensive search
sourceType: SearchSourceType.WEB,
timeout: 120000, // Wait up to 2 minutes
onProgress: (status) => {
console.log(`Found ${status.resultCount} results so far...`)
},
})
console.log(`Found ${result.web.length} web sources`)
console.log(`Session ID: ${result.sessionId}`)
// Add selected sources
const addedIds = await sdk.sources.add.web.addDiscovered('notebook-id', {
sessionId: result.sessionId,
webSources: result.web.slice(0, 5), // Top 5
})Web Search (Advanced)
Method: sdk.sources.add.web.search(notebookId, options) → sdk.sources.add.web.getResults(notebookId, sessionId) → sdk.sources.add.web.addDiscovered(notebookId, options)
Example: source-web-search-advanced.ts
Description: MULTI-STEP WORKFLOW - For cases where you want to see results and make decisions at each step. Returns intermediate results so you can validate, filter, or select before adding sources.
Workflow Steps:
search()- Start search, returnssessionIdimmediatelygetResults(sessionId)- Get discovered sources (can call multiple times to poll)addDiscovered(sessionId, selectedSources)- Add your selected sources
Step 1: Start Search
Method: sdk.sources.add.web.search(notebookId, options)
Parameters:
notebookId: string- The notebook ID (required)options: SearchWebSourcesOptionsquery: string- Search query (required)sourceType?: SearchSourceType-WEB(default) orGOOGLE_DRIVEmode?: ResearchMode-FAST(default) orDEEP(web only)
Returns: Promise<string> - Session ID (required for steps 2 and 3)
Step 2: Get Results
Method: sdk.sources.add.web.getResults(notebookId, sessionId?)
Parameters:
notebookId: string- The notebook ID (required)sessionId?: string- Session ID from step 1 (optional - if omitted, returns all results)
Returns: Promise<{ web: DiscoveredWebSource[], drive: DiscoveredDriveSource[] }>
Step 3: Add Discovered Sources
Method: sdk.sources.add.web.addDiscovered(notebookId, options)
Parameters:
notebookId: string- The notebook ID (required)options: AddDiscoveredSourcesOptionssessionId: string- Session ID from step 1 (required)webSources?: DiscoveredWebSource[]- Web sources to adddriveSources?: DiscoveredDriveSource[]- Drive sources to add
Returns: Promise<string[]> - Array of added source IDs
Usage:
// Step 1: Start search
const sessionId = await sdk.sources.add.web.search('notebook-id', {
query: 'quantum computing',
mode: ResearchMode.FAST,
})
// Step 2: Poll for results (you control when/how often)
let results
do {
await new Promise(r => setTimeout(r, 2000)) // Wait 2 seconds
results = await sdk.sources.add.web.getResults('notebook-id', sessionId)
console.log(`Found ${results.web.length} sources...`)
} while (results.web.length === 0)
// Step 3: Filter and add selected sources
const relevant = results.web.filter(s => s.url.includes('arxiv.org'))
const addedIds = await sdk.sources.add.web.addDiscovered('notebook-id', {
sessionId,