Skip to main content

Use OpenAI (ChatGPT, Image Generation)

Totalum allows you to use OpenAI's API without the need to register for an OpenAI account. You can use it directly through the Totalum SDK or API.


📚 Setup Required: For installation and usage of the Totalum SDK or API, see the Installation Guide.


No need to register on OpenAI — Totalum handles the API access for you.

Chat Completion

Create a chat completion


//body the openai chat completion body, more info here: https://platform.openai.com/docs/api-reference/chat/create
const bodyExample={
// see the openai api docs for more info
messages: [
{content: 'You are a math specialist assistant', role: 'system'},
{content: 'how I can resolve a matrix', role: 'user'}
//etc...
],
model: 'gpt-4.1-mini',
max_tokens: 200,
}

const result = await totalumClient.openai.createChatCompletion(bodyExample);
const chatCompletion = result.data;
// returns the completion provided by openai api


Image Generation

Generate images from text prompts using OpenAI's image generation model.

Generate an image


const result = await totalumClient.openai.generateImage({
prompt: 'A professional product photo of a red sneaker on a white background',
fileName: 'red-sneaker',
size: '1024x1024', // optional: '1024x1024', '1536x1024' (landscape), '1024x1536' (portrait), 'auto'
quality: 'low', // optional: 'low' (fastest), 'medium', 'high', 'auto'
output_format: 'png', // optional: 'png', 'jpeg', 'webp'
background: 'auto' // optional: 'transparent' (requires png), 'opaque', 'auto'
});

const { fileName, imageUrl } = result.data;
// fileName: the file ID stored in Totalum (e.g. 'abc123.png')
// imageUrl: a signed URL to directly access the generated image

Minimal example:


const result = await totalumClient.openai.generateImage({
prompt: 'A cute cartoon cat',
fileName: 'cartoon-cat'
});

const { fileName, imageUrl } = result.data;
console.log('Image URL:', imageUrl);

Generate an image with transparent background


const result = await totalumClient.openai.generateImage({
prompt: 'A company logo with the letter T in blue',
fileName: 'logo',
background: 'transparent',
output_format: 'png' // transparent requires png format
});

const { fileName, imageUrl } = result.data;


Image Editing

Edit or transform existing images using OpenAI's image editing model. You can:

  • Edit parts of an image (e.g. change clothes while keeping the face)
  • Use images as style references
  • Combine multiple images
  • Apply masked editing

Edit an image


const result = await totalumClient.openai.editImage({
prompt: 'Change ONLY the clothing to a blue suit. Keep the face, hair, and background EXACTLY the same.',
imageUrls: ['https://example.com/photo.jpg'], // 1-16 image URLs
fileName: 'edited-photo',
input_fidelity: 'high', // 'high' preserves details (faces, features) — use for editing. 'low' allows creative freedom — use for style references.
size: '1024x1024', // optional
quality: 'low', // optional
output_format: 'png' // optional
});

const { fileName, imageUrl } = result.data;
// fileName: the file ID stored in Totalum
// imageUrl: a signed URL to the edited image

Combine multiple images


const result = await totalumClient.openai.editImage({
prompt: 'Combine these two images into a single scene: place the person from the first image in the landscape from the second image',
imageUrls: [
'https://example.com/person.jpg',
'https://example.com/landscape.jpg'
],
fileName: 'combined-scene',
input_fidelity: 'low' // 'low' for creative combination
});

const { fileName, imageUrl } = result.data;

Use an image as style reference


const result = await totalumClient.openai.editImage({
prompt: 'Create a new product photo in the same visual style as the reference image, but showing a blue backpack',
imageUrls: ['https://example.com/style-reference.jpg'],
fileName: 'styled-product',
input_fidelity: 'low' // 'low' for style transfer
});

const { fileName, imageUrl } = result.data;

Use the generated image in a Totalum record

After generating or editing an image, you can attach it to a record's file property:


// 1. Generate the image
const imageResult = await totalumClient.openai.generateImage({
prompt: 'Professional headshot photo',
fileName: 'headshot'
});

// 2. Use the fileName to attach it to a record's file property
await totalumClient.crud.editRecordProperties('employee', employeeId, {
profile_photo: { name: imageResult.data.fileName }
});