Skip to content

Storage, HTTP and secrets

Every function comes with storage, outbound HTTP, secrets, environment variables and logs. Nothing to set up or connect.

Each function has its own key-value storage. Values you write stay there across requests, deploys and rollbacks, so a counter, a cache or a small record of state survives a new version of your code. No other function can read it.

Language Read Write
JavaScript db.get('visits') db.set('visits', 42)
TypeScript storage.get("visits") (a string; "" when unset) storage.set("visits", "42")
Python hive.db.get("visits", 0) hive.db.set("visits", 42)
Go hivekit.StorageGetJSON("visits", &v) hivekit.StorageSetJSON("visits", v)
Rust storage::get_json::<i64>("visits") storage::set_json("visits", &v)

For larger or shared data, connect to a DockHive database or a Hive Buckets bucket over HTTP.

Call any public API with the built-in http module’s fetch. The request and response are JSON:

const HTTP = '0xbb511886ad14a78759cdf7d39eb4ec884dc9218958c7568ae7626537ef727677'
const res = hive.tryCall(HTTP, 'fetch', {
method: 'POST',
url: 'https://api.example.com/v1/items',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ name: 'pen' }),
timeout_ms: 5000,
})
// res = { status: 201, headers: { ... }, body: '...' }, or null if the request failed

Request: method, url, headers, body (a string), optional body_encoding: "base64" for binary bodies, optional timeout_ms.

Response: status, headers (repeated headers joined with , ), body, and body_encoding: "base64" when the response isn’t UTF-8 text.

  • http and https URLs on ports 80, 443, 8080 and 8443.
  • Only public addresses. Private, loopback, link-local and cloud-metadata addresses are refused, including when a public host name resolves to one.
  • Redirects aren’t followed: a 3xx comes back to your code as is, so you decide whether to follow it.
  • Up to 10 seconds per request (less when your function’s own time limit is closer), 6 MB per request body and per response body, and 50 requests per run.
  • Bytes sent and received count as bandwidth.

In Settings > Allowed outbound hosts, list the hosts your function may reach, one per line: api.example.com, or *.example.com for its subdomains (up to 50). Leave it empty to allow any public host. A good safeguard for functions that handle untrusted input.

Store API keys, tokens and passwords in Settings > Secrets. Values are encrypted, never shown again after you save them: the console and the API list only their names.

Read a secret from your code with the secrets module:

const SECRETS = '0x1d142710be03a758244c1f2f40615c23123c4033f435dbab16b0df490515255b'
const token = hive.callRaw(SECRETS, 'get', 'API_TOKEN')
SECRETS = "0x1d142710be03a758244c1f2f40615c23123c4033f435dbab16b0df490515255b"
token = hive.call_raw(SECRETS, "get", "API_TOKEN")

Reading a secret that isn’t set fails with not_found. Names look like API_TOKEN (capital letters, digits and _, starting with a letter or _, up to 64 characters). A function can have up to 100 secrets of up to 32 KB each.

For plain configuration (not secrets), set Settings > Environment variables, one NAME=value per line, up to 4 KB in total. They arrive in every request as request.env, and you can also read one with the env module, which returns "" when it isn’t set:

const ENV = '0x8b5ff77cfa96b0215a236ebf141f0361cbf83d592cf27f041397f596b1470f8e'
const storeName = hive.callRaw(ENV, 'get', 'STORE_NAME')

console.log (JavaScript), hive.log (TypeScript, Python), hivekit.Logf (Go) and log (Rust) all write to the function’s Logs, next to an entry for every request (status, duration), schedule run, build and error. The last 500 entries per function are kept.

To log with a level, call the log module directly:

LOG = "0x3586923c83c95e54cbd377612c0f8fe931b5b5bf7644d4e1f91557d6e28cfce4"
hive.call_raw(LOG, "write", {"level": "warn", "message": "stock is low"})

Follow logs from your terminal with dockhive functions logs <name> -f.

The starters already define these addresses. If you call the modules directly, use hive.call / hive.tryCall (JavaScript, TypeScript), hive.call / hive.try_call / hive.call_raw (Python), hivekit.Call (Go) or hivekit::call / call_json (Rust).

Module Address Function Input → output
http 0xbb511886ad14a78759cdf7d39eb4ec884dc9218958c7568ae7626537ef727677 fetch request JSON → response JSON
secrets 0x1d142710be03a758244c1f2f40615c23123c4033f435dbab16b0df490515255b get "NAME" → the value; fails with not_found
env 0x8b5ff77cfa96b0215a236ebf141f0361cbf83d592cf27f041397f596b1470f8e get "NAME" → the value, or ""
log 0x3586923c83c95e54cbd377612c0f8fe931b5b5bf7644d4e1f91557d6e28cfce4 write {"level", "message"} → ""

tryCall returns null (None in Python) and call raises. To see why, ask the same module for its last error in this run:

const HTTP = "0xbb511886ad14a78759cdf7d39eb4ec884dc9218958c7568ae7626537ef727677";
const res = hive.tryCall(HTTP, "fetch", "{\"method\":\"GET\",\"url\":\"https://example.com/\"}");
if (res === null) hive.log("fetch failed: " + hive.call(HTTP, "last_error", ""));

Typical messages: not_found, port 22 is not allowed (80, 443, 8080, 8443).

Go:

const httpModule = "0xbb511886ad14a78759cdf7d39eb4ec884dc9218958c7568ae7626537ef727677"
in, _ := json.Marshal(map[string]string{"method": "GET", "url": "https://example.com/"})
out, err := hivekit.Call(httpModule, "fetch", in)

Rust:

const HTTP: &str = "0xbb511886ad14a78759cdf7d39eb4ec884dc9218958c7568ae7626537ef727677";
let res = call_json(HTTP, "fetch", &json!({ "method": "GET", "url": "https://example.com/" }))?;

Each built-in call uses a small, fixed amount of compute plus a little per byte sent and received.