Billing

The API uses account credits just like the web interface. See section below for 'Create a new fine-tune' for development purposes using branch=fast. Once you're ready for production, you can purchase credits and adjust the quantity on the checkout page to how much you need.

Buy creditsBuy bulk $3 - min 200 fine-tunes

Fair use

Current limit is 14 prompts per fine-tune on average, each prompt generating 8 images. Total 112 images on average. There are no exceptions. Some apps claim to provide 100 avatars - meaning ~100 images.

The API was built with the idea that users type prompts manually and authentically. We additionally accounted for 7 automatic prompts that might be added by the system to ease the user and get users acquainted with the system.

We urge app builders against commoditization of the system. Most people would not be able to mentally process 100 images, and this might make the service look cheap.

Consider instead providing a custom unique experience: Let the user choose amongst a few styles/prompts/themes. Consider allowing the user to enter prompts but then augment those with some clever prompt engineering (e.g: https://huggingface.co/spaces/daspartho/prompt-extend https://promptmakr.com/) or maybe allow them to search by keyword through Lexica or other API (e.g: https://prompthero.com/) and adjust the prompt with the `sks class_name` for them.

Authorization

Astria uses Authorization header to authenticate requests. You can get an API key in your account page.

Generate API Key

Postman

Experimental Postman collection is available here. Note that the automatic code generation is not optimal and is missing headers like Authorization and Content-Type.

Postman collection

Community SDKs

Aaron Brand published a Python client for the API:

Python SDK

Tune resource

Get a list of all fine-tunes

curl -X GET -H "Authorization: Bearer $API_KEY" https://api.astria.ai/tunes[...array of finetunes...]

Create a new fine-tune

If you would like to experiment with the API for testing purposes free, use branch=fast - This is will return hard-coded prompt results within a minute

callback is a URL that will be called when the fine-tune is done processing. The callback is a POST request where the body contains the tune object. Once the fine-tune is done processing, prompts will start processing.

steps - training steps is also an optional parameter which we recommend leaving out in order to allow better defaults set by the system.

Note this request is a multi-part encoded form request, i.e: not JSON

Example with NodeJS/Javascript
import FormData from 'form-data';
import fs from 'fs';
import fetch from "node-fetch";

const API_KEY = 'sd_XXXX';
const DOMAIN = 'https://api.astria.ai';

function createTune() {
  let formData = new FormData();
  formData.append('tune[title]', 'John Smith');
  formData.append('tune[branch]', 'fast');
  formData.append('tune[name]', 'man');
  // Load all JPGs from ./samples directory and append to FormData
  let files = fs.readdirSync('./samples');
  files.forEach(file => {
    formData.append('tune[images][]', fs.createReadStream(`./samples/${file}`), file);
  });
  formData.append('tune[callback]', 'https://optional-callback-url.com/to-your-service-when-ready');

  let options = {
    method: 'POST',
      headers: { 'Authorization': 'Bearer ' + API_KEY },
      body: formData
  };
  return fetch(DOMAIN + '/tunes', options)
    .then(r => r.json())
}
Example with cURL
curl -X POST -H "Authorization: Bearer $API_KEY" https://api.astria.ai/tunes \
          -F tune[callback]="https://optional-callback-url.com/to-your-service-when-ready" \
          -F tune[title]="my portrait" \
          -F tune[branch]="" \
          -F tune[name]=man \
          -F "tune[images][]=@1.jpg" \
          -F "tune[images][]=@2.jpg" \
          -F "tune[images][]=@3.jpg" \
          -F "tune[images][]=@4.jpg"
Example with cURL with image_urls
curl -X POST -H "Authorization: Bearer $API_KEY" https://api.astria.ai/tunes \
          -F tune[callback]="https://optional-callback-url.com/to-your-service-when-ready" \
          -F tune[title]="grumpy cat" \
          -F tune[branch]="" \
          -F tune[name]=cat \
          -F "tune[image_urls][]=https://i.imgur.com/HLHBnl9.jpeg" \
          -F "tune[image_urls][]=https://i.imgur.com/HLHBnl9.jpeg" \
          -F "tune[image_urls][]=https://i.imgur.com/HLHBnl9.jpeg" \
          -F "tune[image_urls][]=https://i.imgur.com/HLHBnl9.jpeg"
{ "id": 1, "images": [ "http://assets.astria.ai/1.jpg", "http://assets.astria.ai/2.jpg", "http://assets.astria.ai/3.jpg", "http://assets.astria.ai/4.jpg" ], "name": "person", "steps": null, "ckpt_url": null, "created_at": "2022-10-06T14:06:09.088Z", "updated_at": "2022-10-06T14:06:09.139Z", "url": "http://api.astria.ai/tunes/26.json" }

Get one fine-tune

Note that ckpt_url is only available after the fine-tune is done processing, and is a pre-signed URL which expires after 60 minutes.

curl -X GET -H "Authorization: Bearer $API_KEY" https://api.astria.ai/tunes/1{
  "id": 1,
  "images": [
    "http://assets.astria.ai/1.jpg",
    "http://assets.astria.ai/2.jpg",
    "http://assets.astria.ai/3.jpg",
    "http://assets.astria.ai/4.jpg"
  ],
  "name": "man",
  "steps": null,
  "ckpt_url": "https://....",
  "created_at": "2022-10-06T14:06:09.088Z",
  "updated_at": "2022-10-06T14:06:09.139Z",
  "url": "http://api.astria.ai/tunes/26.json"
}

Delete one fine-tune

curl -X DELETE -H "Authorization: Bearer $API_KEY" https://api.astria.ai/tunes/1

Prompt resource

Create a new prompt

callback is a URL that will be called when the prompt is done processing. The callback is a POST request where the body contains the prompt object.

Note that you can control `cfg_scale`, `seed`, `steps` as well, however #{Settings.site_name) provides some good defaults for these.

curl -X POST -H "Authorization: Bearer $API_KEY" https://api.astria.ai/tunes/26/prompts \ -F prompt[text]="a painting of sks man in the style of alphonse mucha" \ -F prompt[negative_prompt]="extra leg" \ -F prompt[callback]="https://optional-callback-url.com/to-your-service-when-ready"{ "id": 29, "callback": "https://optional-callback-url.com/to-your-service-when-ready", "text": "a painting of sks man in the style of alphonse mucha", "negative_prompt": "3 legs, 4 legs", "cfg_scale": null, "steps": null, "seed": null, "trained_at": null, "started_training_at": null, "created_at": "2022-10-06T16:12:54.505Z", "updated_at": "2022-10-06T16:12:54.505Z", "tune_id": 26, "url": "http://api.astria.ai/tunes/26/prompts/29.json" }

Get all prompts of a fine-tune

Use the offset parameter to paginate through the results.

curl -X GET -H "Authorization: Bearer $API_KEY" https://api.astria.ai/tunes/1/prompts?offset=0[...array of prompts...]