Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/anil-matcha/open-generative-ai/llms.txt

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

Every request to the Muapi.ai API — whether it is submitting a generation job, polling for results, uploading a file, or checking your account balance — must include a valid API key. Muapi.ai uses a custom x-api-key header for authentication rather than the conventional Authorization: Bearer scheme. Open Generative AI stores this key in browser localStorage and attaches it to every outbound request made by muapi.js, so you only need to enter it once in the app UI. When integrating muapi.js directly in your own code, you pass the key as the first argument to every exported function.

Getting an API Key

1

Create a Muapi.ai account

Sign up for a free account at https://muapi.ai. New accounts start with a free credit allocation so you can begin generating immediately.
2

Open the Access Keys page

Navigate to https://muapi.ai/access-keys. This page lists all your API keys and lets you create new ones.
3

Create a new key and copy the key value

Click Create Key, give it a descriptive label (e.g. open-generative-ai-local), and confirm. The page will display the generated key value immediately after creation.
Copy the key value — the long string of characters displayed after you create the key. Do not enter the key’s name or label. The app authenticates with the value, not the human-readable name, and entering a label will result in 401 Unauthorized errors on every request.

Passing the Key in Requests

All requests to https://api.muapi.ai must include the key in the x-api-key HTTP header.
curl -X POST https://api.muapi.ai/api/v1/flux-schnell-image \
  -H 'Content-Type: application/json' \
  -H 'x-api-key: YOUR_API_KEY' \
  -d '{"prompt": "a futuristic cityscape at night"}'
Use x-api-key, not Authorization: Bearer YOUR_API_KEY. Requests that use the Authorization header instead of x-api-key will be rejected.

In the Open Generative AI App

When you enter your API key in the app’s key-entry modal, it is saved to browser localStorage under the key muapi_key. The key is read from storage on every generation request and passed to muapi.js as the first argument. It is never sent to any server other than api.muapi.ai. You can inspect or clear the stored key at any time in your browser’s developer tools:
// Read the stored key
localStorage.getItem('muapi_key');

// Clear the stored key (forces the key-entry modal to reappear)
localStorage.removeItem('muapi_key');

In the JavaScript Client

When importing muapi.js functions directly, pass your API key as the first argument:
import { generateImage } from 'studio'; // or from packages/studio/src/muapi.js

const result = await generateImage('your-api-key-here', {
  model: 'flux-schnell',
  prompt: 'a futuristic cityscape at night',
  aspect_ratio: '16:9'
});

console.log(result.url); // URL of the generated image
The key is forwarded into the x-api-key header of every HTTP request made by the function, including the initial POST to submit the job and each subsequent GET to poll for the result.

Checking Your Balance

Use getUserBalance to confirm your key is valid and to see your remaining credit balance before running expensive generation jobs:
import { getUserBalance } from 'studio';

const balance = await getUserBalance('your-api-key-here');
console.log(balance); // { credits: 1000, ... }
This calls GET /api/v1/account/balance with the x-api-key header. A successful response confirms the key is active and returns your current credit information.

Authentication Errors

If the API returns an HTTP 401 (Unauthorized) or HTTP 403 (Forbidden) response, muapi.js does two things:
  1. Throws an error with the HTTP status and response body, halting the generation.
  2. Dispatches a muapi:auth-required custom event on the window object (when running in a browser), carrying the status code and error message as event.detail.
The studio UI listens for this event to automatically show the API key entry modal. You can listen for the same event in your own application:
window.addEventListener('muapi:auth-required', (event) => {
  console.error('API key rejected:', event.detail.status, event.detail.message);
  // Prompt the user to re-enter their API key
});
Common reasons for 401/403 errors:
  • The key value was copied incorrectly (e.g. whitespace included, or the label was entered instead of the value)
  • The key has been deleted or rotated in the Muapi.ai dashboard
  • The account has exhausted its credit balance
Start with a free Muapi.ai account to get free credits with no payment required. When you need more capacity, paid plans are available at https://muapi.ai/pricing.

Build docs developers (and LLMs) love