@hostfunc/sdk

The runtime SDK is split into core function APIs plus optional AI, agent, and vector modules.

SDK API Reference

Use @hostfunc/sdk for new functions. Submodules (/ai, /agent, /vector) call internal APIs and require proper workspace integration setup.

fn.executeFunction

await fn.executeFunction<T = unknown>(slug: string, input?: unknown, options?: { timeoutMs?: number }): Promise<T>

Invoke another function by org/slug with lineage and call-depth protection.

Arguments

NameTypeRequiredDescription
slugstring (orgSlug/fnSlug)YesTarget function identifier.
inputunknownNoJSON-serializable payload sent to the downstream function.
options.timeoutMsnumberNoOptional per-call timeout (bounded by runtime limits).

Returns

Parsed downstream JSON response (or raw text for non-JSON responses).

Throws

  • FN_CALL_DEPTH when depth is exceeded or cycle detected.
  • FN_CALL_TIMEOUT when the child call exceeds timeout.
  • FN_EXECUTE_FAILED when downstream returns non-2xx or network failure occurs.

secret.get

await secret.get(key: string): Promise<string | null>

Retrieve an optional secret value for the current function.

Arguments

NameTypeRequiredDescription
keystringYesSecret key configured in function settings.

Returns

Secret string value or null when not configured.

Throws

  • INFRA_EXECUTE_FAILED if secret service cannot be reached/authenticated.

secret.getRequired

await secret.getRequired(key: string): Promise<string>

Retrieve a required secret. Throws a structured missing_secret error when unset.

Arguments

NameTypeRequiredDescription
keystringYesSecret key configured in function settings.

Returns

Secret string value.

Throws

  • MISSING_SECRET when key is missing (includes key + docsUrl detail).

SDK Code Examples

Core composition pattern

Call one function from another with a required secret.

typescript
import fn, { secret } from "@hostfunc/sdk";export async function main(input: { customerId: string }) {  const apiKey = await secret.getRequired("CLAUDE_API_KEY");  const report = await fn.executeFunction("org/generate-report", {    customerId: input.customerId,    apiKey,  });  return await fn.executeFunction("org/post-to-slack", { report, channel: "#alerts" });}

Best Practices

  • Prefer @hostfunc/sdk for all new code; keep @hostfunc/fn only for legacy compatibility.
  • Use org/slug identifiers, not mutable user-provided values.
  • Keep chained payloads compact and pass IDs/references for large data.
  • Configure integrations in /dashboard/settings/integrations before using AI/vector helpers.

Related Documentation