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
| Property | Value |
|---|---|
| Platform | OpenAI |
| Category | AI / ML (Custom) |
| Setup Complexity | Medium |
| Official Integration | No |
| Data Synced | Content, Embeddings, Insights, Predictions |
| Auth Method | API 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:
- An OpenAI account with API access
- An API key from the OpenAI dashboard
- A Brevo account with API access
- A Tajo account with connector permissions
- Sufficient OpenAI API credits for your expected usage
Authentication
API Key Authentication
OpenAI uses Bearer token authentication for all API requests:
# Set your API keysexport OPENAI_API_KEY=sk-your-api-keyexport TAJO_API_KEY=your_tajo_api_keyexport BREVO_API_KEY=your_brevo_api_key// All requests require the Authorization headerconst headers = { 'Authorization': `Bearer ${process.env.OPENAI_API_KEY}`, 'Content-Type': 'application/json'};
// For organization-scoped accessconst 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.7Content 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.7API Endpoints
| Endpoint | Method | Description |
|---|---|---|
https://api.openai.com/v1/responses | POST | Create AI responses (Responses API) |
https://api.openai.com/v1/chat/completions | POST | Generate text completions |
https://api.openai.com/v1/embeddings | POST | Create text embeddings |
https://api.openai.com/v1/images/generations | POST | Generate images |
https://api.openai.com/v1/audio/speech | POST | Text-to-speech generation |
https://api.openai.com/v1/audio/transcriptions | POST | Speech-to-text transcription |
https://api.openai.com/v1/moderations | POST | Content moderation |
https://api.openai.com/v1/models | GET | List 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 linesconst 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 sentimentconst 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 clusteringconst 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 clusteringRate Limits
| Model | RPM (Requests/Min) | TPM (Tokens/Min) | RPD (Requests/Day) |
|---|---|---|---|
| gpt-4o | 500 | 30,000 | 10,000 |
| gpt-4o-mini | 500 | 200,000 | 10,000 |
| text-embedding-3-small | 500 | 1,000,000 | 10,000 |
| dall-e-3 | 5 | N/A | 200 |
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
| Issue | Cause | Solution |
|---|---|---|
| 401 Unauthorized | Invalid API key | Verify key in OpenAI dashboard |
| 429 Rate Limited | Too many requests | Implement exponential backoff |
| 500 Server Error | OpenAI outage | Check status.openai.com and retry |
| Truncated response | max_tokens too low | Increase max_tokens parameter |
| Poor content quality | Temperature too high | Lower temperature for consistency |
Debug Mode
connectors: openai: debug: true log_level: verbose log_prompts: false # Don't log prompts in production log_usage: trueBest Practices
- Cache responses - Store generated content to reduce API calls and costs
- Use structured outputs - Request JSON responses for reliable parsing
- Implement retry logic - Handle rate limits with exponential backoff
- Monitor token usage - Track consumption to control costs
- Use appropriate models - Use gpt-4o-mini for simple tasks, gpt-4o for complex ones
- 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
Related Resources
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
| Repository | Commit | Languages / formats | Files |
|---|---|---|---|
| openai/openai-openapi | e1cb7a8 | license (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
- OpenAPI spec for the OpenAI API
- The most recent OpenAPI specification for the OpenAI API can be found here:
- https://app.stainless.com/api/spec/documented/openai/openapi.documented.yml
- To see the most recent manually updated version of the OpenAPI spec, refer to
- this branch:
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.