Skip to main content

The Core of Mynth app

In apps like Mynth, API Keys are the core, as they are used in almost every requests to provide authentication and authorization. Same happens here. You can create API Keys, and then use them in your requests to get access to the API. In Mynth, API Keys have some additional configuration, like a spending limit, and a spending limit period.

Spending limits

Spending limits are a way to limit the amount of money that can be spent with an API Key. This is useful to avoid unexpected costs on specific API Keys. By default, spending limits are disabled. To enable them, you need to set a spending limit and a spending limit period. The limit applies to the entire period. For example, if you set a spending limit of 10.00 USD and a spending limit period of month, the limit will be applied to the entire month. If the spending limit is exceeded, the API will return an error. After the period is over, the spending limit is reset and API Key can be used again. You can change the spending limit at any time.
Please be aware that due to the nature of our API and the fact of using cost estimation, the spending limit is not guaranteed to be exact. The difference is usually tiny, but there can be a slight difference in the actual cost.For example if limit was set to 10.00 USD, the actual final cost limit might be 10.004 or 9.997 USD.

Managing API Keys

Creating an API Key

To create an API Key you need to have an account on mynth.io and be logged in. Then follow these simple steps:
  1. Go to the API Keys page in the Dashboard.
  2. Click on the “Create API Key” button.
  3. Optional: Set name for the API Key. It can help later to identify the key in the dashboard.

Setting a spending limit

  1. Go to the API Keys page in the Dashboard.
  2. Find the API Key you want to set a spending limit for.
  3. Click on the edit icon (pencil icon) to the right of the API Key.
  4. Set spending limit (needs to be more than 0.00)
  5. Set spending limit period (day, week, month)
  6. Click on the “Save” button.

Using API Key

With Mynth SDK

To use an API Key with Mynth SDK, set MYNTH_API_KEY environment variable with the API Key value. The client will automatically try to use the API Key from the environment variable. You can also pass the API Key explicitly as a string to the constructor.
import { Mynth } from "@mynth/sdk";

const mynth = new Mynth({ apiKey: `mak_1234567890` });
Wehn using the functional version of the SDK, by default we will try to use the API Key from the environment variable (MYNTH_API_KEY). If you want to explicitly set the API Key you have 2 options. Option 1: You can use the global configure function to set it in entry point of the app.
import { configure } from "@mynth/sdk";

configure({ apiKey: `mak_1234567890` });
Option 2: You can pass the API Key explicitly as a string to the function.
import { generateImage } from "@mynth/sdk";

const result = await generateImage(
    { prompt: "A beautiful sunset" }, 
    { apiKey: `mak_1234567890` }
);

Manually

To use an API Key manually, just include it in the Authorization header as a bearer token.
Authorization: Bearer mak_1234567890
With curl:
curl -X POST https://api.mynth.io/image/generate \
-H "Authorization: Bearer mak_1234567890" \
-H "Content-Type: application/json" \
-d '{"prompt": "A beautiful sunset"}'