How to use the content_type global variable to control response formats in Reasoning Flows or Workshops.

🧩 Defining content_type in Reasoning Flows

Overview

In Arpia, every Reasoning Flow or Workshop executed through an AutoAPI can control how its response is returned to the requester.

This is done by defining a global variable called content_type.

The content_type variable tells Arpia what format to use when sending the final API response — whether it should be JSON, plain text, HTML, an image, or another format.

This capability allows Builders to decide not only what data to return, but how it should be delivered to external systems or user interfaces.


💡 When to Use It

You should define a content_type variable in your Reasoning Flow whenever the result you’re returning is not JSON.

For example:

  • When generating an HTML report.
  • When returning an image, file, or PDF.
  • When sending a simple text message instead of a JSON structure.

If you do not define content_type, Arpia will automatically use the default type:


🧠 How It Works

During execution, Reasoning Flows can read and write global variables.

When a variable named content_type is present in the global scope at the end of the flow, Arpia uses its value to set the HTTP response header for the AutoAPI call.

This means that the content_type variable behaves like a declarative instruction to Arpia, defining how the final output should be interpreted by the client.


⚙️ Supported Values for content_type

ValueDescriptionTypical Use
application/jsonDefault structured responseData, structured output
text/plainPlain textLogs, messages, or summaries
text/htmlHTML contentReports or formatted outputs
application/xmlXML structureIntegrations with older systems
text/csvCSV dataData exports
application/pdfBinary PDFReports or documents
image/pngPNG imageCharts, diagrams, or visual outputs
image/jpegJPEG imagePhotos or generated illustrations
application/octet-streamRaw binaryGeneric file or binary stream

🧩 Example Scenarios

1. Returning JSON (default)

When your Reasoning Flow outputs structured data such as key–value pairs, you don’t need to specify anything — Arpia automatically sets the response to application/json.

2. Returning a Plain Text Message

If your Reasoning Flow produces a simple message or log line, set content_type to text/plain.

The AutoAPI will then respond as plain text, making it easier to use in scripts or monitoring tools.

3. Returning an HTML Report

When your Flow generates formatted content — for example, a report or an HTML snippet to be embedded in a dashboard — define content_type as text/html.

This allows external systems (like browsers or visualization tools) to render the response directly.

4. Returning a File or Image

For Flows that generate files, charts, or images, use application/pdf, image/png, or image/jpeg.

Arpia will send the response as a binary stream, allowing clients to download or display it directly.


🧭 Best Practices

  • Always define content_type explicitly when the output is not JSON.
  • Ensure the response variable you produce matches the format indicated by the content_type.
  • Use UTF-8 for text formats (text/plain, text/html, etc.) to ensure multilingual support.
  • For large binary data (images, PDFs), consider saving the file as an Arpia File Object and returning the file’s access URL.
  • Keep your Flows predictable — use the same content_type consistently for similar outputs.

🚀 Summary

ElementPurpose
Global Variable: content_typeDefines how Arpia should format the API response
Default: application/jsonUsed when no content type is specified
Who Defines It: Builder, inside the Reasoning Flow or Workshop
Impact: Controls the HTTP Content-Type header for the AutoAPI output

By defining content_type as an Arpia Global Variable, Builders gain full control over the presentation and integration format of their Reasoning Flow outputs — transforming each AutoAPI into a flexible, multi-modal endpoint capable of returning exactly the type of data the consuming system expects.