OpenAI Connector

Connect OpenAI to Brevo through Tajo to leverage AI-powered content generation, customer sentiment analysis, intelligent segmentation, and predictive analytics for your marketing automation workflows.

Overview

PropertyValue
PlatformOpenAI
CategoryAI / ML (Custom)
Setup ComplexityMedium
Official IntegrationNo
Data SyncedContent, Embeddings, Insights, Predictions
Auth MethodAPI Key (Bearer Token)

Features

  • AI content generation - Generate email subject lines, body copy, and CTAs with GPT models
  • Customer sentiment analysis - Analyze support tickets and feedback for sentiment scoring
  • Smart segmentation - Use embeddings to cluster customers by behavior patterns
  • Predictive analytics - Forecast churn, LTV, and purchase propensity
  • Multi-language content - Generate marketing content in any supported language
  • Image generation - Create campaign visuals with DALL-E integration

Prerequisites

Before you begin, ensure you have:

  1. An OpenAI account with API access
  2. An API key from the OpenAI dashboard
  3. A Brevo account with API access
  4. A Tajo account with connector permissions
  5. Sufficient OpenAI API credits for your expected usage

Authentication

API Key Authentication

OpenAI uses Bearer token authentication for all API requests:

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 Key Security

Never expose your OpenAI API key in client-side code. Always use environment variables and server-side requests. Rotate keys periodically via the OpenAI dashboard.

Configuration

Basic Setup

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

Content Generation Templates

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 Endpoints

EndpointMethodDescription
https://api.openai.com/v1/responsesPOSTCreate AI responses (Responses API)
https://api.openai.com/v1/chat/completionsPOSTGenerate text completions
https://api.openai.com/v1/embeddingsPOSTCreate text embeddings
https://api.openai.com/v1/images/generationsPOSTGenerate images
https://api.openai.com/v1/audio/speechPOSTText-to-speech generation
https://api.openai.com/v1/audio/transcriptionsPOSTSpeech-to-text transcription
https://api.openai.com/v1/moderationsPOSTContent moderation
https://api.openai.com/v1/modelsGETList available models

Code Examples

Initialize Connector

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 Email Content

// 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;

Customer Sentiment Analysis

// 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 }
});

Smart Segmentation with Embeddings

// 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

Rate Limits

ModelRPM (Requests/Min)TPM (Tokens/Min)RPD (Requests/Day)
gpt-4o50030,00010,000
gpt-4o-mini500200,00010,000
text-embedding-3-small5001,000,00010,000
dall-e-35N/A200

Rate Limit Headers

Monitor rate limit headers (x-ratelimit-remaining-requests, x-ratelimit-remaining-tokens) in API responses to implement proactive throttling and avoid 429 errors.

Troubleshooting

IssueCauseSolution
401 UnauthorizedInvalid API keyVerify key in OpenAI dashboard
429 Rate LimitedToo many requestsImplement exponential backoff
500 Server ErrorOpenAI outageCheck status.openai.com and retry
Truncated responsemax_tokens too lowIncrease max_tokens parameter
Poor content qualityTemperature too highLower temperature for consistency

Debug Mode

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

Best Practices

  1. Cache responses - Store generated content to reduce API calls and costs
  2. Use structured outputs - Request JSON responses for reliable parsing
  3. Implement retry logic - Handle rate limits with exponential backoff
  4. Monitor token usage - Track consumption to control costs
  5. Use appropriate models - Use gpt-4o-mini for simple tasks, gpt-4o for complex ones
  6. Validate outputs - Always validate AI-generated content before sending to customers

Security

  • Bearer token auth - API keys transmitted via Authorization header
  • Server-side only - Never expose API keys in client-side code
  • Key rotation - Rotate API keys regularly via OpenAI dashboard
  • Usage monitoring - Set spending limits in OpenAI billing settings
  • Content moderation - Use the Moderations API to filter unsafe content
  • Data privacy - Review OpenAI’s data usage policies for your use case

Open-Source Implementation Map

This section is derived from official or public repository material discovered for the OpenAI connector. Use it as the engineering companion to the setup guide above: it shows where the API surface lives, what implementation assets exist, and how Tajo should translate them into reliable Brevo sync behavior.

Repository Snapshot

RepositoryCommitLanguages / formatsFiles
openai/openai-openapie1cb7a8license (1), Markdown (1)2

Integration Shape

graph LR
Source["OpenAI API / repository"] --> Auth["Auth and scopes"]
Source --> Objects["Objects, events, and schemas"]
Auth --> Tajo["Tajo connector runtime"]
Objects --> Tajo
Tajo --> Brevo["Brevo contacts, attributes, lists, campaigns"]
Tajo --> Ops["Backfill, cursor, retries, logs"]

What To Reuse

Tajo Revamp Checklist

  • Keep authentication setup aligned with the vendor docs and the public repository’s current API shape.
  • Map primary resources into explicit Tajo sync objects with stable external IDs.
  • Prefer cursor-based or updated-at incremental sync where the API exposes it; otherwise document the fallback.
  • Treat webhook handlers as idempotent and replay-safe, especially for order, contact, ticket, and campaign events.
  • Capture pagination, rate limits, retry headers, and partial-failure behavior in connector smoke tests.
  • Keep examples small and runnable against sandbox or test-mode accounts.

Sources

Subscribe to updates

developer-docs

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

auto-detect
AI Assistant

Hi! Ask me anything about the docs.