# HTTP functions

Source: https://cubibase.com/docs/functions/http

Also available: [Markdown version](https://cubibase.com/docs/functions/http.md) · [llms.txt](https://cubibase.com/llms.txt) · [full site content](https://cubibase.com/llms-full.txt)

Every deployed function with an HTTP trigger is an HTTPS endpoint at https://{slug}.api.cubibase.com/functions/{name}. The gateway enforces authentication, signatures and limits before your code runs.

## The endpoint

GET, POST, PUT, PATCH, DELETE and OPTIONS are supported. Headers, query parameters, extra path segments and the raw body reach your handler unchanged. The response your handler returns is the response the caller receives (bounded by the platform response-size limit).

**Call a public function**

```http
curl "https://example-project.api.cubibase.com/functions/hello-world?name=Ada"

# {"message":"Hello, Ada!","invocationId":"…"}
```

> **note**: The raw body is preserved byte-for-byte. Never re-serialize a parsed body before verifying a webhook signature — verify against request.body.

## Authentication modes

Authentication is a gateway setting, independent of your code and of payload signatures. JWT is the default when you create a function.

| Mode | Caller must present | Use for |
| --- | --- | --- |
| `jwt` (default) | Authorization: Bearer <end-user access JWT> from CubiBase Auth | Calls from your signed-in users |
| `public` | Nothing | Webhooks and open endpoints — pair with signature verification |
| `api_key` | A project secret API key (cb_sec_…) in the apikey header or as Bearer | Server-to-server calls from trusted code |
| `internal` | Not externally reachable at all | Functions invoked only by other CubiBase machinery |

**JWT mode · call as a signed-in user**

```http
curl -X POST "https://example-project.api.cubibase.com/functions/openai-proxy" \
  -H "Authorization: Bearer <USER_ACCESS_JWT>" \
  -H "content-type: application/json" \
  -d '{"prompt": "Summarize row-level security in one sentence."}'
```

**API key mode · call from your server**

```http
curl -X POST "https://example-project.api.cubibase.com/functions/send-email" \
  -H "apikey: cb_sec_YOUR_SECRET_KEY" \
  -H "content-type: application/json" \
  -d '{"to": "ada@example.com", "subject": "Welcome", "text": "Glad you are here."}'
```

> **Secret keys stay server-side**: API-key mode requires the secret key (cb_sec_…), not the publishable key. Never ship a secret key in a browser or mobile bundle. An internal-mode function answers 404 on the public host.

## Gateway responses

| Status | When |
| --- | --- |
| `401` | Missing/invalid JWT, missing/invalid secret key, or a failed signature check |
| `404` | Unknown project host, unknown function, no enabled HTTP trigger, or internal-only function |
| `409` | The function is disabled, or has no active deployment yet |
| `413` | The request body exceeds the platform request-size limit |
| `402` | The monthly invocation or compute allowance is exhausted |
| `429` | The per-project HTTP rate limit or concurrent-execution limit is reached — retry shortly |
| `500` | The function threw or exceeded its configured timeout (status recorded as timeout) — details are in Executions & Logs, not in the caller response |
| `502` | The function returned an oversized response |

Internal errors never leak infrastructure details to the caller. The invocation id in the error body matches the execution record in the Console.

## Additional resources

- [Signed payloads](https://cubibase.com/docs/functions/signatures) HMAC verification and third-party webhooks.
- [Templates](https://cubibase.com/docs/functions/templates) Stripe and GitHub webhook starting points.
