How to Call the OpenAI API from a Workflow

Send prompts to the OpenAI API from any Spojit workflow with the HTTP Requests connector, read the answer, get structured JSON back, and know when Spojit's built-in AI steps are the simpler choice.

What This Integration Does

Spojit has AI built in: any Connector node in Agent Mode runs on the models Spojit offers, billed in Spojit credits, with tool calling and governance included. You do not need an OpenAI account for that. Calling the OpenAI API directly makes sense in a few cases: your organisation has standardised on OpenAI and wants usage on its own OpenAI bill, you need a specific OpenAI model or endpoint (embeddings, moderation, image generation, audio transcription), or you are moving an existing OpenAI prompt into a workflow without changing it. This tutorial sets up an OpenAI connection on the HTTP Requests connector and shows the request patterns you will use most.

Each call is a single, stateless HTTP request: the prompt goes in, the answer comes back in the step's output, and nothing is kept between runs unless you store it. Errors (rate limits, invalid keys) fail the step, so Spojit's retry settings and run history apply as for any other step.

Prerequisites

  • An OpenAI platform account with billing set up, and a project API key from the OpenAI dashboard. Use a project dedicated to Spojit so you can see and limit its usage separately.
  • The model ID you want, from OpenAI's models page. Model names change often, so copy the current ID rather than relying on an old example.

Step 1: Create the OpenAI Connection

In Spojit, go to Connections and add an HTTP Requests connection:

  • Base URL: https://api.openai.com/v1
  • Auth Method: Bearer token
  • Token: your OpenAI project API key

Spojit stores the key with the connection and sends it as Authorization: Bearer ... on every request, so it never appears in workflow steps.

Step 2: Send a Prompt with the Responses API

Add a Connector node on the OpenAI connection with http-post:

  • url: /responses
  • body:
    {
      "model": "YOUR_MODEL_ID",
      "instructions": "You are a concise assistant for an online store's operations team.",
      "input": "Summarise this customer email in one sentence and say whether it needs a refund: {{ input.email_text }}"
    }

Name the output ai. The answer is in {{ ai.data.output }}: a list of output items, where the item with type message has a content list whose output_text entry holds the text. Run the step once and copy the exact path from the output panel (for a simple prompt it is usually the last item's first content entry). The output_text shortcut you may see in OpenAI's examples is added by OpenAI's SDKs and is not in the raw HTTP response.

Step 3: Get Structured JSON Back

To use the answer in a Condition or write it to another system, ask for JSON that matches a schema. Add a text.format object to the body:

{
  "model": "YOUR_MODEL_ID",
  "input": "Classify this support email: {{ input.email_text }}",
  "text": {
    "format": {
      "type": "json_schema",
      "name": "ticket_classification",
      "strict": true,
      "schema": {
        "type": "object",
        "properties": {
          "category": { "type": "string", "enum": ["refund", "shipping", "product", "other"] },
          "urgent": { "type": "boolean" },
          "summary": { "type": "string" }
        },
        "required": ["category", "urgent", "summary"],
        "additionalProperties": false
      }
    }
  }
}

The message text is then a JSON string. Parse it with JSON Tools parse, and route on category and urgent in a Condition.

Step 4: Other Endpoints

The same connection reaches the rest of the API:

  • Chat Completions (if you are porting older code): POST /chat/completions with { "model", "messages": [ { "role": "user", "content": "..." } ] }; the answer is in choices[0].message.content.
  • Embeddings: POST /embeddings with { "model", "input" }, for similarity search in your own database.
  • Moderation: POST /moderations with { "input" }, to screen user-submitted text before it is published.

Step 5: Use the Answer

Downstream steps reference the parsed answer like any other output: post it to Slack, write it to a Monday.com item, add it as a note on a Shopify order, or use it in the body of a Send Email node.

Tips

  • Built-in first: for most tasks (summarising, classifying, drafting, extracting), an Agent Mode step with a Response Schema does the same job with no extra account, and it can also call tools. Use OpenAI directly when you specifically need it.
  • Keep prompts in one place: put long instructions in a Transform node and reference them, so several workflows share the same wording.
  • Control cost: set a monthly budget on the OpenAI project, and send only the text the model needs, not whole records.
  • Data handling: check your organisation's policy before sending customer data to any external AI provider, and remove fields that are not needed for the task.

Common Pitfalls

  • Reading the wrong path: the raw response nests the text inside output and content. Copy the path from a real run rather than writing output_text.
  • Rate limits: calling OpenAI inside a Loop over hundreds of items can hit your account's limits and return 429. Process in smaller batches or add a delay.
  • Retired model IDs: OpenAI retires models over time. A step that suddenly returns a model-not-found error needs a current model ID.
  • Template quoting: when you insert text into input, quotes and newlines in that text must stay valid JSON. Put the whole value in a template ("input": "{{ prompt }}" with prompt built in a Transform) rather than concatenating raw text into the body.

Testing

Run the workflow manually with a short test input and check the step output: the status should be 200 and the text should be where you expect. Then try an input with quotes and line breaks to make sure the request stays valid before connecting real data.

Learn More

Ready to build this?

Start on the free plan: 500 AI credits a month, no card needed.

Start free

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.