Docs

Authorization

All endpoints are protected and require you to include your API key.

create an API key in your settings here https://www.mimpi.ai/dashboard/settings.

Add the key in the Authorization header like this:

await fetch({{ENDPOINT}}, {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Authorization": `Bearer {{API_KEY}}`
	},
});

Test keys

You can create Test keys in addition to production keys. When using a test key the API will respond with sample data and won’t increment your usage. Use test keys when you’re implementing the API in your app.

Note: when using test keys your provided callback will called immediately, and models and prompts will be marked as complete right away.

Payment and billing

Before you can train any models, you’ll need to connect your payment card in the dashboard. Otherwise you’ll receive an error.

Every time a model is completed it will count towards your usage. If the model fails to generate you won’t be charged.

You will be charged for usage on a daily basis, or immediately if your usage reaches 100 USD or more.

Uploading images

Before creating your models you’ll need to upload the training images. You do so using signed URLs. Signed urls are a safe and fast method to upload files from the client. Here’s how it works:

const imageIds = []

for (const file of files){
	// get the signed url
	const result = await fetch("https://www.mimpi.ai/api/signedUrl", 
	  headers: {
	    "Content-Type": "application/json",
	    "Authorization": `Bearer {{API_KEY}}`
		},
	)
	const { data: { id, url } } = await result.json()

	// Upload a single file
	await fetch(url, {
		method: "PUT",
		headers: {
			"Content-Type": "image/jpeg"
		},
		body: file
	})
	
	// save id for creating model later
	imageIds.push(id)
}

// Then use imageIds when creating a new model.

Models (fine-tune)

Before you can generate any images you’ll need to train a model. Training a model takes time, so you’ll need to provide a callback that will be called when the training is done.

Creating a model requires you to provide the “subject”, and “imageIds”. It is recommended to provide at least 20 images - see how to upload images below. We also recommend to provide a “callbackUrl” which will be called when the training is complete.

Create a model

await fetch("https://www.mimpi.ai/api/model", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Authorization": `Bearer {{API_KEY}}`
	},
	body: JSON.stringify({
			subject: "man",
			callbackUrl: "https://myapp.com/api/callback",
			imageIds: imageIds // image IDs from previous step
	})
});

// returns 
{
	"data": Model object
}

Get a model

await fetch("https://www.mimpi.ai/api/model/{ID}", {
  method: "GET",
  headers: {
    "Content-Type": "application/json",
    "Authorization": `Bearer {{API_KEY}}`
	}
});

// returns 
{
	"data": Model object
}

Model object

{
    "id": string;
    "callbackUrl": string | null;
    "imageUrls": string[];
    "subject": string;
    "createdAt": string;
    "status": "PENDING" | "RUNNING" | "COMPLETED" | "FAILED";
    "progress": number;
    "failedMessage": string | null;
    "isTest": boolean;
    "prompts": {
	    id: string;
	    generatedImages: string[];
	    status: "PENDING" | "RUNNING" | "COMPLETED" | "FAILED";
	  }[]  
}

Prompts (Image generation)

When a model has been created you can start requesting prompts for the model and generate images.

The callbackUrl will be called when the images have been generated.

Create a prompt

await fetch("https://www.mimpi.ai/api/prompt", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Authorization": `Bearer {{API_KEY}}`
	},
	body: JSON.stringify({
			prompt: "sks man in soft light, portrait, in the style of Van Gogh,...",
			callbackUrl: "https://myapp.com/api/callback",
			modelId: "cs123123123",
			imageCount: 4
	})
});

// returns 
{
	"data": Prompt object
}

Get a prompt

await fetch("https://www.mimpi.ai/api/prompt/{ID}", {
  method: "GET",
  headers: {
    "Content-Type": "application/json",
    "Authorization": `Bearer {{API_KEY}}`
	}
});

// returns 
{
	"data": Prompt object
}

Prompt object

{
	id: string;
  callbackUrl?: string | null;
  generatedImages: string[];
  imageCount: number;
  imageSize: number;
  createdAt: string;
  status: "PENDING" | "RUNNING" | "COMPLETED" | "FAILED";
  progress: number;
  failedMessage?: string | null;
  isTest: boolean;
}

Notes:

Currently models and images are stored for 30 days. Reach out to us if you require to store the model for a longer time.

There’s a limit on 30 concurrent models. Reach out if you need more concurrency.

Ready to get started?Sign up for free now.