Aurabase Logo
aurabasedocs
docs›Edge Functions›Text, binary and HTML responses

Return text, binary and HTML

How to send text, images, files or HTML from a function and read them back with the SDK or plain HTTP.

6 min read·Level intermediate·Revised on Oct 12, 2026
This English text was generated automatically from the French original and has not been reviewed yet.
#
Decision

1. Choose a response type

Your function returnsUse responseTypedata is
JSON'json' (default)the parsed value
Plain text, CSV, HTML'text' (or 'json', which also returns the string)a string
An image, a PDF, any bytes'blob' or 'arrayBuffer'a Blob or an ArrayBuffer

The default 'json' mode can carry JSON and text. It cannot carry bytes: if a function answers with a binary content type, the SDK returns the error invalid_response and tells you to pick 'blob' or 'arrayBuffer', so nothing is lost silently.

#
SDK

2. Read it with the SDK

aurabase/functions/export/index.tstypescript
Deno.serve((req) => {
  const { pathname } = new URL(req.url)
  if (pathname === '/csv') {
    return new Response('id,name\n1,Ada\n', { headers: { 'content-type': 'text/csv' } })
  }
  // The 8-byte PNG signature, enough to show bytes round-trip
  const bytes = new Uint8Array([137, 80, 78, 71, 13, 10, 26, 10])
  return new Response(bytes, { headers: { 'content-type': 'image/png' } })
})
client.tstypescript
const csv = await aura.functions.invoke<string>('export', { path: '/csv', responseType: 'text' })
console.log(csv.data) // "id,name\n1,Ada\n"

const img = await aura.functions.invoke<Blob>('export', { responseType: 'blob' })
console.log(img.data?.type, img.data?.size) // "image/png" 8

In a real run with a function returning the bytes 137,80,78,71,13,10,26,10,255,0,1, arrayBuffer returned exactly those 11 bytes and blob returned type=image/png size=11.

With 'text', 'blob' or 'arrayBuffer', the SDK skips the JSON envelope and returns the body of your function as it is. If your function answers with an error status, error.status is that status and error.message is the text your function returned.

#
HTTP

3. Raw mode over HTTP

Add the header X-Aurabase-Invoke-Mode: raw and the platform returns your function's own response: its status, content-type and bytes.

terminalbash
curl -i -X POST "$AURA_URL/v1/functions/export/invoke" \
  -H "apikey: $AURA_ANON_KEY" \
  -H "Content-Type: application/json" \
  -H "X-Aurabase-Invoke-Mode: raw" \
  -d '{"path":"/csv"}' --output export.csv

Without that header, the response is always 200 with an envelope:

envelope.jsonjson
{
  "data": {
    "status": 200,
    "headers": { "content-type": "application/json" },
    "body": { "greeting": "Hello, Ada!" },
    "logs": [],
    "duration_ms": 74
  },
  "meta": null
}

In the envelope, body is the parsed JSON, the text of your response when it is UTF-8 and not JSON, or null when the body is empty or binary.

In raw mode every response from your function carries x-aurabase-invoke-origin: function. A response without it comes from the gateway or the runtime. This is how the SDK tells a 503 returned by your code from a platform outage.

#
Headers

4. Which headers survive

In raw mode your response headers are filtered, because they are served from the platform's own origin.

HeaderResult
content-typeKept. Defaults to application/octet-stream if you set none.
Custom headers (x-custom-out, cache-control, …)Kept.
set-cookieRemoved. A function cannot set cookies.
access-control-*Removed. CORS is decided by the gateway.
x-aura-*, x-internal-tokenRemoved.
content-security-policy, strict-transport-security, x-content-type-optionsSet by the platform, whatever you send.
content-length, transfer-encoding, connectionRecomputed.

A response that can run scripts (text/html, application/xhtml+xml, image/svg+xml, application/xml, text/xml) is served with a sandboxing content security policy. Real response for a function returning text/html:

response headerstext
content-type: text/html
content-security-policy: default-src 'none'; frame-ancestors 'none'; sandbox
x-content-type-options: nosniff

Your HTML is served, but without cookie, storage or script access to your project's origin. Use Storage or your own domain to host a real web page.

Last updated · Oct 12, 2026