Skip to main content

Authentication with Mynth

API keys are the primary way to authenticate requests to the Mynth API. You can manage multiple keys for different projects or environments. All Mynth API keys start with the prefix mak_ (Mynth API Key).

Spending Limits

To help you control costs, Mynth supports configurable spending limits per API key. This is particularly useful for preventing unexpected overages.

How it works

  • Status: By default, spending limits are disabled (unlimited).
  • Periods: You can set limits for day, week, or month.
  • Resets: Limits reset automatically at the start of each period at 00:00 UTC.
  • Enforcement: If a limit is exceeded, the API will return a 402 Payment Required or 429 Too Many Requests error until the next period begins.
Cost Estimation: Due to the nature of cost estimation for dynamic workloads, the spending limit may not be exact. There might be a tiny variance (e.g., ±0.01%) in the final actual cost versus the limit.

Managing API Keys

Creating a Key

  1. Go to the API Keys page.
  2. Click Create API Key.
  3. (Optional) Provide a Name to identify the key later.
  4. Copy the key and store it securely; it will only be shown once.

Setting a Spending Limit

  1. Locate your key in the API Keys list.
  2. Click the Edit (pencil) icon.
  3. Enter a limit amount (e.g., 50.00).
  4. Select the reset period (Daily, Weekly, or Monthly).
  5. Click Save.

Using Your API Key

With Mynth SDK

Initialize the Mynth client with your API key. We recommend using environment variables to store your key safely.
import { Mynth } from "@mynthio/sdk";

const mynth = new Mynth({ 
  apiKey: process.env.MYNTH_API_KEY 
});

Manual Usage (cURL)

Include your API key in the Authorization header as a Bearer token.
curl -X POST https://api.mynth.io/image/generate \
  -H "Authorization: Bearer mak_..." \
  -H "Content-Type: application/json" \
  -d '{"prompt": "A beautiful sunset"}'