OpenAI

Generate text, images, and audio using OpenAI models.

AI and MLAPI key9 actionsAll integrations

On this page
  1. Connect
  2. Call it from a workflow
  3. Actions (9)
  4. ask_chatgpt
  5. generate_image
  6. text_to_speech
  7. transcribe
  8. vision_prompt
  9. ask_assistant
  10. custom_api_call
  11. extract-structured-data
  12. translate
  13. Details

Connect

Auth type: API key (secret_text). Pass the provider's API key or token as the connection's credential. It is sealed at rest and only opened on the server when an action runs.

  • From your agent: integrations {action: "connect", piece, credentials, env} stores the credentials for dev, prod or all. Answers name the fields, never the values.
  • Or set the integration's project secrets with the secrets tool (SLACK_BOT_TOKEN, DISCORD_WEBHOOK_URL, TELEGRAM_BOT_TOKEN, TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN …): a call uses the connection, else those secrets. integrations {action: "catalog", piece} lists which ones work.
  • Try one action now with integrations {action: "call", piece, piece_action, input}. It really sends.

Call it from a workflow

step.ctx.integrations.invoke("openai", action, input) resolves with the provider's answer and rejects when OpenAI isn't connected or refuses. Wrap it in step.run so a retry sends once. See step.ctx. Its actions run through the integration runner, which the server's operator turns on: integrations {action: "catalog", piece: "openai"} says whether yours can call it.

Workflow
// workflows/notify.ts: call OpenAI when a booking is confirmed
import { on } from "@appbricx/workflows";

export const tellOpenai = on.transition("booking", "status", "confirmed", async (_event, step) => {
  // Recorded once: a retry doesn't send it twice. Rejects when OpenAI isn't connected.
  const output = await step.run("OpenAI", () =>
    step.ctx.integrations.invoke("openai", "ask_chatgpt", {
      "model": "<model>",
      "prompt": "<question>",
      "maxTokens": 1
    }),
  );
  step.ctx.log("OpenAI answered", output);
});
Try it from your agent
{
  "name": "integrations",
  "arguments": {
    "project_id": "<project-id>",
    "action": "call",
    "piece": "openai",
    "piece_action": "ask_chatgpt",
    "input": {
      "model": "<model>",
      "prompt": "<question>",
      "maxTokens": 1
    },
    "env": "dev"
  }
}
From another backend (connector proxy)
curl -X POST "$APP_ORIGIN/__appbricx/connector-proxy/openai/ask_chatgpt" \
  -H "Authorization: Bearer $APP_KEY" \
  -H "content-type: application/json" \
  -d '{"props":{"model":"<model>","prompt":"<question>","maxTokens":1}}'

Actions

ask_chatgpt

Ask ChatGPT. Ask ChatGPT anything you want!

InputTypeDescription
modelrequiredid (picked from your account)The model which will generate the completion. Some models are suitable for natural language tasks, others specialize in code.
promptrequiredlong textQuestion
temperatureoptionalnumberControls randomness: Lowering results in less random completions. As the temperature approaches zero, the model will become deterministic and repetitive.
maxTokensrequirednumberThe maximum number of tokens to generate. Requests can use up to 2,048 or 4,096 tokens shared between prompt and completion depending on the model. Don't set the value to maximum and leave some token…
topPoptionalnumberAn alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top …
frequencyPenaltyoptionalnumberNumber between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.
presencePenaltyoptionalnumberNumber between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the mode's likelihood to talk about new topics.
memoryKeyoptionaltextA memory key that will keep the chat history shared across runs and flows. Keep it empty to leave ChatGPT without memory of previous messages.
rolesoptionalJSONArray of roles to specify more accurate response

generate_image

Generate Image. Generate an image using text-to-image models

InputTypeDescription
modelrequiredid (picked from your account)The model which will generate the image.
promptrequiredlong textPrompt
resolutionoptionalid (picked from your account)The resolution to generate the image in.
qualityoptionalid (picked from your account)Standard is faster, HD has better details.

text_to_speech

Text-to-Speech. Generate an audio recording from text

InputTypeDescription
textrequiredlong textThe text you want to hear.
modelrequiredone of "tts-1" | "tts-1-hd"The model which will generate the audio.
speedoptionalnumberThe speed of the audio. Minimum is 0.25 and maximum is 4.00.
voicerequiredone of "alloy" | "echo" | "fable" | "onyx" | "nova" | "shimmer"The voice to generate the audio in.
formatrequiredone of "mp3" | "opus" | "aac" | "flac"The format you want the audio file in.
fileNameoptionaltextThe name of the output audio file (without extension).

transcribe

Transcribe Audio. Transcribe audio to text using whisper-1 model

InputTypeDescription
audiorequiredfileAudio file to transcribe
languageoptionalone of "es" | "it" | "en" | "pt" | "de" | "ja" | "pl" | "ar" | "af" | "az" | "bg" | "bs"Language of the audio file the default is en (English).

vision_prompt

Vision Prompt. Ask GPT a question about an image

InputTypeDescription
imagerequiredfileThe image URL or file you want GPT's vision to read.
promptrequiredlong textWhat do you want ChatGPT to tell you about the image?
detailoptionalid (picked from your account)Control how the model processes the image and generates textual understanding.
temperatureoptionalnumberControls randomness: Lowering results in less random completions. As the temperature approaches zero, the model will become deterministic and repetitive.
maxTokensoptionalnumberThe maximum number of tokens to generate. Requests can use up to 2,048 or 4,096 tokens shared between prompt and completion, don't set the value to maximum and leave some tokens for the input. The ex…
topPoptionalnumberAn alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top …
frequencyPenaltyoptionalnumberNumber between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.
presencePenaltyoptionalnumberNumber between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the mode's likelihood to talk about new topics.
rolesoptionalJSONArray of roles to specify more accurate response

ask_assistant

Ask Assistant. Ask a GPT assistant anything you want!

InputTypeDescription
assistantrequiredid (picked from your account)The assistant which will generate the completion.
promptrequiredlong textQuestion
memoryKeyoptionaltextA memory key that will keep the chat history shared across runs and flows. Keep it empty to leave your assistant without memory of previous messages.

custom_api_call

Custom API Call. Make a custom API call to a specific endpoint

InputTypeDescription
urlrequiredobject (depends on other props)url
methodrequiredone of "GET" | "POST" | "PATCH" | "PUT" | "DELETE" | "HEAD"Method
headersrequiredobjectAuthorization headers are injected automatically from your connection.
queryParamsrequiredobjectQuery Parameters
body_typeoptionalone of "none" | "json" | "form_data" | "raw"Body Type
bodyoptionalobject (depends on other props)Body
response_is_binaryoptionalbooleanEnable for files like PDFs, images, etc.
failsafeoptionalbooleanNo Error on Failure
timeoutoptionalnumberTimeout (in seconds)
followRedirectsoptionalbooleanFollow redirects

extract-structured-data

Extract Structured Data from Text. Returns structured data from provided unstructured text.

InputTypeDescription
modelrequiredid (picked from your account)Model
textrequiredlong textUnstructured Text
paramsrequiredarrayData Definition

translate

Translate Audio. Translate audio to text using whisper-1 model

InputTypeDescription
audiorequiredfileAudio file to translate

Details

Id
openai
Category
AI and ML
Tags
ai, gpt, chatgpt, dall-e, whisper
Package
@activepieces/piece-openai@0.7.5
Runs
Through the integration runner