Tiny fetch wrapper that injects the auth header. Every API call goes through here so the master key (or per-agent key) is applied consistently and errors surface as plain Error throws.
// Source: https://github.com/agenticmail/agenticmail | License: MIT | Copyright 2026 Ope Olatunji
// Provided via justclaw.it.com; keep this notice with the code.
// Tiny fetch wrapper that injects the auth header. Every API call goes
// through here so the master key (or per-agent key) is applied
// consistently and errors surface as plain Error throws.
import { state, API_URL } from './state.js';
export async function apiGet(path, opts = {}) {
const r = await fetch(`${API_URL}/api/agenticmail${path}`, {
headers: { Authorization: `Bearer ${opts.agentKey ?? state.masterKey}` },
});
if (!r.ok) throw new Error(`${r.status} ${path}`);
return await r.json();
}
export async function apiPost(path, body, opts = {}) {
const r = await fetch(`${API_URL}/api/agenticmail${path}`, {
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search 40K more like it.
Get a free API key