
2Slides Team
4 min read

AI 代理人正在徹底改變軟體內容的生成方式。AI 簡報代理人能夠生成、客製化並交付專業的簡報投影片,作為自動化工作流程的一部分——從客戶關係管理 (CRM) 管道到內部報告工具,無所不包。
本指南將引導您使用 2Slides API 打造一個可投入生產的簡報代理人。
簡報代理人通常遵循以下流程:
使用者請求 → 代理人邏輯 → 2Slides API → 輪詢任務 → 交付結果 ↓ 上下文收集 (資料、範本、品牌資產)
請在 2slides.com 註冊,並在 2slides.com/api 建立 API 金鑰。
npm install node-fetch dotenv
import fetch from 'node-fetch'; class PresentationAgent { constructor(apiKey) { this.apiKey = apiKey; this.baseUrl = 'https://2slides.com/api/v1'; } async generateSlides({ topic, themeId, language = 'en', resolution = '2K' }) { // 步驟 1:開始生成 const response = await fetch(`${this.baseUrl}/slides/generate`, { method: 'POST', headers: { 'Authorization': `Bearer ${this.apiKey}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ userInput: topic, themeId, responseLanguage: language, resolution, mode: 'async' }) }); const job = await response.json(); if (!response.ok) throw new Error(job.error || 'Generation failed'); // 步驟 2:輪詢直到完成 return await this.waitForCompletion(job.jobId); } async waitForCompletion(jobId, maxWait = 300000) { const start = Date.now(); while (Date.now() - start < maxWait) { const response = await fetch(`${this.baseUrl}/jobs/${jobId}`, { headers: { 'Authorization': `Bearer ${this.apiKey}` } }); const status = await response.json(); if (status.status === 'success') return status; if (status.status === 'failed') throw new Error('Generation failed'); await new Promise(r => setTimeout(r, 3000)); } throw new Error('Generation timed out'); } async generateFromFile({ fileUrl, prompt, themeId }) { const response = await fetch(`${this.baseUrl}/slides/create-pdf-slides`, { method: 'POST', headers: { 'Authorization': `Bearer ${this.apiKey}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ fileUrl, userInput: prompt, themeId, mode: 'async' }) }); const job = await response.json(); return await this.waitForCompletion(job.jobId); } async generateWithDesign({ topic, referenceImageUrl, resolution = '2K' }) { const response = await fetch(`${this.baseUrl}/slides/create-like-this`, { method: 'POST', headers: { 'Authorization': `Bearer ${this.apiKey}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ userInput: topic, designStyle: { global: { referenceImageUrl } }, resolution, mode: 'async' }) }); const job = await response.json(); return await this.waitForCompletion(job.jobId); } async addNarration({ jobId, mode = 'single', voice = 'Charon' }) { const response = await fetch(`${this.baseUrl}/slides/generate-narration`, { method: 'POST', headers: { 'Authorization': `Bearer ${this.apiKey}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ jobId, mode, voice, contentMode: 'concise' }) }); return await response.json(); } } // 用法 const agent = new PresentationAgent('sk-2slides-xxx'); const result = await agent.generateSlides({ topic: 'Q1 2026 Business Review', themeId: 'mckinsey-theme-id', resolution: '2K' }); console.log('下載:', result.downloadUrl);
import requests import time class PresentationAgent: def __init__(self, api_key): self.api_key = api_key self.base_url = 'https://2slides.com/api/v1' self.headers = { 'Authorization': f'Bearer {api_key}', 'Content-Type': 'application/json' } def generate_slides(self, topic, theme_id=None, language='en', resolution='2K'): response = requests.post( f'{self.base_url}/slides/generate', headers=self.headers, json={ 'userInput': topic, 'themeId': theme_id, 'responseLanguage': language, 'resolution': resolution, 'mode': 'async' } ) response.raise_for_status() job = response.json() return self._wait_for_completion(job['jobId']) def generate_from_file(self, file_url, prompt, theme_id=None): response = requests.post( f'{self.base_url}/slides/create-pdf-slides', headers=self.headers, json={ 'fileUrl': file_url, 'userInput': prompt, 'themeId': theme_id, 'mode': 'async' } ) response.raise_for_status() job = response.json() return self._wait_for_completion(job['jobId']) def _wait_for_completion(self, job_id, max_wait=300): start = time.time() while time.time() - start < max_wait: response = requests.get( f'{self.base_url}/jobs/{job_id}', headers=self.headers ) status = response.json() if status['status'] == 'success': return status if status['status'] == 'failed': raise Exception('Generation failed') time.sleep(3) raise TimeoutError('Generation timed out') # 用法 agent = PresentationAgent('sk-2slides-xxx') result = agent.generate_slides('AI Trends 2026', resolution='4K') print(f"下載: {result['downloadUrl']}")
為不同的使用案例預先配置主題:
const TEMPLATES = { 'pitch-deck': { themeId: 'apple-id', resolution: '2K' }, 'quarterly-review': { themeId: 'mckinsey-id', resolution: '2K' }, 'training': { themeId: 'corporate-id', resolution: '1K' }, 'social-media': { themeId: 'saul-bass-id', resolution: '4K', aspectRatio: '1:1' }, }; async function generateByType(type, topic) { const config = TEMPLATES[type]; return agent.generateSlides({ topic, ...config }); }
連接到您的資料來源:
async function weeklyReport(dataSource) { // 1. 獲取最新資料 const data = await dataSource.getWeeklyMetrics(); // 2. 格式化為簡報輸入 const topic = `Weekly Report: Revenue $${data.revenue}, Users ${data.users}, Churn ${data.churn}%`; // 3. 生成投影片 const result = await agent.generateSlides({ topic, themeId: 'mckinsey-id' }); // 4. 交付 await slackBot.postMessage('#team-updates', `Weekly report ready: ${result.downloadUrl}`); }
在一個管道中生成投影片 + 旁白 + 影片:
async function fullPresentation(topic) { // 1. 生成投影片 const slides = await agent.generateSlides({ topic }); // 2. 添加語音旁白 await agent.addNarration({ jobId: slides.jobId, mode: 'multi', voice: 'Charon' }); // 3. 下載含音訊的檔案 const download = await fetch(`${agent.baseUrl}/slides/download-slides-pages-voices`, { method: 'POST', headers: agent.headers, body: JSON.stringify({ jobId: slides.jobId }) }); return download.json(); }
可以 — 該 API 專為生產環境使用而設計。對商業應用沒有任何限制。
API 透過速率限制處理並行請求。對於高用量需求,請聯繫 2Slides 團隊以獲取企業級限制。
目前,請透過 jobs 端點進行輪詢。Webhook 支援已列入開發藍圖。
打造您的簡報代理人 — 在 2Slides 取得您的 API 金鑰 並開始以程式化方式生成投影片。
Create stunning AI-powered presentations in seconds. Transform your ideas into professional slides with 2slides AI Agent.
Try For FreeYour AI Agent for slides. Save time, shine faster with intelligent presentation creation.
All services online© 2026 2slides. All rights reserved.