Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintfax.com/docs/llms.txt

Use this file to discover all available pages before exploring further.

Outcome

You will wire mintfax into an LLM tool-use loop that sends faxes, handles errors deterministically, and retries safely with idempotency keys. You will also learn how mintfax’s agent-discoverable artifacts (OpenAPI spec, llms.txt, structured errors) plug into your agent’s tool definitions.

Prerequisites

  • A mintfax sandbox API key (fx_test_...). See Sandbox if you need one.
  • Node.js 18+ or Python 3.10+.
  • Familiarity with your LLM provider’s function-calling or tool-use API (Claude tool use, OpenAI function calling, or similar).

Step 1: Define the fax-sending tool

Your agent needs a tool definition that maps to POST /v1/fax. The mintfax OpenAPI spec at https://api.mintfax.com/v1/openapi.yaml (also at https://mintfax.com/.well-known/openapi.yaml) has the full request shape. Here is a minimal version:
const sendFaxTool = {
  name: "send_fax",
  description: "Send a fax via the mintfax API. Returns a fax ID for status tracking.",
  input_schema: {
    type: "object",
    properties: {
      to: {
        type: "string",
        description: "Recipient fax number in E.164 format, e.g. +12015550100"
      },
      file_url: {
        type: "string",
        description: "URL of the document to fax (PDF or TIFF)"
      },
      idempotency_key: {
        type: "string",
        description: "UUID to prevent duplicate submissions on retry"
      }
    },
    required: ["to", "file_url", "idempotency_key"]
  }
};
Make idempotency_key a required parameter in your tool definition. Agents retry on transient failures, and without an idempotency key each retry creates a new fax. With one, mintfax returns the cached response for 24 hours. See Idempotency for the full behavior.

Step 2: Implement the tool handler

When the LLM invokes the tool, your handler calls the mintfax API and returns a structured result. Pass the full error shape back so the LLM can decide what to do next.
async function handleSendFax({ to, file_url, idempotency_key }) {
  const res = await fetch("https://api.mintfax.com/v1/fax", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.MINTFAX_API_KEY}`,
      "Content-Type": "application/json",
      "Idempotency-Key": idempotency_key,
    },
    body: JSON.stringify({ to, file_url }),
  });

  const data = await res.json();

  if (!res.ok) {
    return {
      success: false,
      error: data.error,
      message: data.message,
      action: data.action,
      docs: data.docs,
      retryable: res.status === 503 || res.status === 429,
    };
  }

  return {
    success: true,
    fax_id: data.id,
    status: data.status,
  };
}
Returning action and docs alongside the error code gives the LLM enough context to act without guessing. See Errors for the complete catalog and the meaning of each action value.

Step 3: Handle errors in the agent loop

Every mintfax error response carries machine-readable fields that agents can branch on:
FieldPurposeExample
errorStable error code for branching logicinsufficient_balance
messageHuman-readable explanation"Balance too low to send fax"
actionDeterministic next steptop_up_balance
docsLink to the relevant docs page/errors/insufficient-balance
Instruct your agent to branch on the error code and action field, not the message string. Message text can change between API versions; error codes and actions are stable. An agent that reads action: top_up_balance can surface a clear next step. An agent that parses prose will eventually break. For retryable errors (HTTP 503 fax_busy, HTTP 429 rate limits), reuse the same idempotency key and respect the Retry-After header. Cap retries at five attempts with exponential backoff.

Step 4: Track fax status with events

After submitting a fax, your agent can either poll GET /v1/fax/{id} or receive webhook events. Polling is simpler for agent loops because it avoids spinning up an HTTP server inside the agent process.
async function pollFaxStatus(faxId, maxAttempts = 10) {
  for (let i = 0; i < maxAttempts; i++) {
    const res = await fetch(
      `https://api.mintfax.com/v1/fax/${faxId}`,
      {
        headers: {
          Authorization: `Bearer ${process.env.MINTFAX_API_KEY}`,
        },
      }
    );
    const data = await res.json();

    if (data.status === "delivered" || data.status === "failed") {
      return data;
    }

    await new Promise((r) => setTimeout(r, 5000));
  }

  return { status: "polling_timeout" };
}
If your production integration needs real-time delivery confirmation, use webhooks instead. See Events for the event schema and Webhook signing for payload verification.

Step 5: Use agent-discoverable artifacts

mintfax publishes three kinds of artifacts that LLM agents and developer tools can consume without human intervention: OpenAPI spec. The spec lives at https://api.mintfax.com/v1/openapi.yaml and https://mintfax.com/.well-known/openapi.yaml. It is OpenAPI 3.1 with x-codeSamples on every endpoint and full error response schemas. Most agent frameworks include an OpenAPI-to-tool converter; feed the spec to it and skip writing tool definitions by hand. llms.txt. Mintlify auto-generates llms.txt and llms-full.txt at the docs root (mintfax.com/docs/llms.txt and mintfax.com/docs/llms-full.txt). These follow the emerging llms.txt convention for service descriptions that LLMs can discover. Mintlify also sets Link and X-Llms-Txt HTTP headers on every docs page. Structured errors. Every error response includes error, message, action, and docs fields. Your agent branches on the code, follows the action hint, and links the user to the relevant docs page if needed.

Prompt design tips

A few things worth putting in your agent’s system prompt:
  • Require the agent to generate a UUID idempotency key before every send_fax call. Reuse the same key on retry.
  • Instruct it to read error and action from failed responses, not message.
  • Include the sandbox success number +15005550001 so the agent can test without touching real fax infrastructure. See Sandbox for the full magic number matrix.
  • Use a sandbox API key (fx_test_...) during development. Sandbox keys cannot route to real destinations.

A note on MCP

MCP is one way to expose tools to LLM agents. A mintfax MCP server would wrap the API endpoints as MCP tools with the same send, poll, and error-handling flow described above. MCP server implementation is planned for a future release. The patterns in this guide apply whether you connect through MCP or through direct function calling.

Verify

Send a test fax to the sandbox success number to confirm everything works:
  1. Set your agent’s API key to a sandbox key (fx_test_...).
  2. Have the agent call send_fax with to set to +15005550001.
  3. Confirm the response contains a fax_id and status: "queued".
  4. Poll or wait for the fax to reach delivered status.

What to do next

  • Idempotency for retry behavior, key expiration, and best practices in automated loops.
  • Errors for the full error catalog with stable codes and action hints.
  • Webhook signing to verify webhook payloads if your agent receives delivery events.
  • Events for the complete list of event types and payload schemas.
  • Sandbox for magic fax numbers and simulated failure scenarios.