OpenAI 连接器

通过 Tajo 将 OpenAI 连接到 Brevo,借助 AI 驱动的内容生成、客户情感分析、智能细分和预测分析,提升您的营销自动化工作流。

概览

属性
平台OpenAI
类别AI / ML(自定义)
设置复杂度中等
官方集成
同步数据内容、向量嵌入、洞察、预测
认证方式API 密钥(Bearer 令牌)

功能

  • AI 内容生成 - 使用 GPT 模型生成邮件主题行、正文内容和行动号召
  • 客户情感分析 - 分析支持工单和反馈以获得情感评分
  • 智能细分 - 使用向量嵌入按行为模式聚类客户
  • 预测分析 - 预测流失、LTV 和购买倾向
  • 多语言内容 - 以任何支持的语言生成营销内容
  • 图像生成 - 通过 DALL-E 集成创建活动视觉素材

前提条件

开始之前,请确保您已具备:

  1. 具有 API 访问权限的 OpenAI 账户
  2. 来自 OpenAI 控制台 的 API 密钥
  3. 具有 API 访问权限的 Brevo 账户
  4. 具有连接器权限的 Tajo 账户
  5. 足够的 OpenAI API 额度以满足预期用量

认证

API 密钥认证

OpenAI 对所有 API 请求使用 Bearer 令牌认证:

Terminal window
# Set your API keys
export OPENAI_API_KEY=sk-your-api-key
export TAJO_API_KEY=your_tajo_api_key
export BREVO_API_KEY=your_brevo_api_key
// All requests require the Authorization header
const headers = {
'Authorization': `Bearer ${process.env.OPENAI_API_KEY}`,
'Content-Type': 'application/json'
};
// For organization-scoped access
const orgHeaders = {
...headers,
'OpenAI-Organization': process.env.OPENAI_ORG_ID,
'OpenAI-Project': process.env.OPENAI_PROJECT_ID
};

API 密钥安全

切勿在客户端代码中暴露您的 OpenAI API 密钥。始终使用环境变量和服务器端请求。定期通过 OpenAI 控制台轮换密钥。

配置

基础设置

connectors:
openai:
enabled: true
model: "gpt-4o"
embedding_model: "text-embedding-3-small"
image_model: "dall-e-3"
features:
content_generation: true
sentiment_analysis: true
smart_segmentation: true
predictive_analytics: true
limits:
max_tokens_per_request: 4096
max_requests_per_minute: 60
temperature: 0.7

内容生成模板

templates:
email_subject:
model: "gpt-4o"
system_prompt: |
You are an expert email marketer. Generate compelling
subject lines that drive open rates.
max_tokens: 100
temperature: 0.8
email_body:
model: "gpt-4o"
system_prompt: |
Generate personalized email content based on customer
data and campaign objectives.
max_tokens: 2048
temperature: 0.7

API 端点

端点方法描述
https://api.openai.com/v1/responsesPOST创建 AI 响应(Responses API)
https://api.openai.com/v1/chat/completionsPOST生成文本补全
https://api.openai.com/v1/embeddingsPOST创建文本向量嵌入
https://api.openai.com/v1/images/generationsPOST生成图像
https://api.openai.com/v1/audio/speechPOST文字转语音
https://api.openai.com/v1/audio/transcriptionsPOST语音转文字
https://api.openai.com/v1/moderationsPOST内容审核
https://api.openai.com/v1/modelsGET列出可用模型

代码示例

初始化连接器

import { TajoClient } from '@tajo/sdk';
const tajo = new TajoClient({
apiKey: process.env.TAJO_API_KEY,
brevoApiKey: process.env.BREVO_API_KEY
});
await tajo.connectors.connect('openai', {
apiKey: process.env.OPENAI_API_KEY,
defaultModel: 'gpt-4o'
});

生成邮件内容

// Generate personalized email subject lines
const response = await fetch('https://api.openai.com/v1/chat/completions', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.OPENAI_API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'gpt-4o',
messages: [
{
role: 'system',
content: 'Generate 5 compelling email subject lines for a product launch.'
},
{
role: 'user',
content: `Product: ${product.name}. Target: ${segment.description}.`
}
],
max_tokens: 200,
temperature: 0.8
})
});
const result = await response.json();
const subjectLines = result.choices[0].message.content;

客户情感分析

// Analyze customer feedback sentiment
const sentimentAnalysis = await fetch(
'https://api.openai.com/v1/chat/completions',
{
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.OPENAI_API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'gpt-4o',
messages: [
{
role: 'system',
content: 'Analyze sentiment. Return JSON: {score: -1 to 1, label: string, topics: string[]}'
},
{ role: 'user', content: customerFeedback }
],
response_format: { type: 'json_object' },
max_tokens: 150
})
}
);
const sentiment = await sentimentAnalysis.json();
await tajo.contacts.update(email, {
attributes: { SENTIMENT_SCORE: JSON.parse(sentiment.choices[0].message.content).score }
});

基于向量嵌入的智能细分

// Generate embeddings for customer clustering
const embeddingResponse = await fetch(
'https://api.openai.com/v1/embeddings',
{
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.OPENAI_API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'text-embedding-3-small',
input: customerDescriptions,
dimensions: 256
})
}
);
const embeddings = await embeddingResponse.json();
// Use embeddings for similarity-based customer clustering

速率限制

模型RPM(请求/分钟)TPM(令牌/分钟)RPD(请求/天)
gpt-4o50030,00010,000
gpt-4o-mini500200,00010,000
text-embedding-3-small5001,000,00010,000
dall-e-35N/A200

速率限制头部

监控 API 响应中的速率限制头部(x-ratelimit-remaining-requestsx-ratelimit-remaining-tokens),实施主动限流以避免 429 错误。

故障排除

问题原因解决方案
401 UnauthorizedAPI 密钥无效在 OpenAI 控制台中验证密钥
429 Rate Limited请求过多实施指数退避
500 Server ErrorOpenAI 故障检查 status.openai.com 并重试
响应被截断max_tokens 过低增加 max_tokens 参数
内容质量差温度过高降低温度以提高一致性

调试模式

connectors:
openai:
debug: true
log_level: verbose
log_prompts: false # Don't log prompts in production
log_usage: true

最佳实践

  1. 缓存响应 - 存储生成的内容以减少 API 调用和成本
  2. 使用结构化输出 - 请求 JSON 响应以便可靠解析
  3. 实施重试逻辑 - 使用指数退避处理速率限制
  4. 监控令牌用量 - 追踪消耗量以控制成本
  5. 使用合适的模型 - 简单任务用 gpt-4o-mini,复杂任务用 gpt-4o
  6. 验证输出 - 在向客户发送前始终验证 AI 生成的内容

安全

  • Bearer 令牌认证 - API 密钥通过 Authorization 头部传输
  • 仅服务器端 - 切勿在客户端代码中暴露 API 密钥
  • 密钥轮换 - 定期通过 OpenAI 控制台轮换 API 密钥
  • 用量监控 - 在 OpenAI 计费设置中设置消费限制
  • 内容审核 - 使用 Moderations API 过滤不安全内容
  • 数据隐私 - 根据使用场景审阅 OpenAI 的数据使用政策

相关资源

Subscribe to updates

developer-docs

Drop your email or phone number — we'll send you what matters next.

auto-detect
AI 助手

你好!关于文档有任何问题都可以问我。