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.

Add to balance

Storage policy

Generated images, training pictures and models, will be automatically deleted 30 days after the training time ended. You may delete the fine-tune object including the trained model, training images, and generated images at any time before.

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

Using Bubble.io

Bubble.io Plugin

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

Branch possible values: sd15, sd21, protogen34, openjourney2

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.

face_crop - Enhanced face cropping. Optional. Defaults to accounts settings

base_tune_id - BETA. Optional. Training on top of former fine-tune or a different baseline model

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[token]', 'sks');
  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())
}

function createTuneImageUrls() {
  let options = {
    method: 'POST',
    headers: { 'Authorization': 'Bearer ' + API_KEY, 'Content-Type': 'application/json' },
    body: JSON.stringify({
      tune: {
        "title": 'My Tune',
        "name": "cat",
        "branch": "fast",
        "image_urls": [
          "https://i.imgur.com/HLHBnl9.jpeg",
          "https://i.imgur.com/HLHBnl9.jpeg",
          "https://i.imgur.com/HLHBnl9.jpeg",
          "https://i.imgur.com/HLHBnl9.jpeg"
        ]
      }
    })
  };
  return fetch(DOMAIN + '/tunes', options)
    .then(r => r.json())
}
Example with cURL and nested prompts
curl -X POST -H "Authorization: Bearer $API_KEY" https://api.astria.ai/tunes \
          -F tune[callback]="https://optional-callback-url.com/webhooks/astria?user_id=1&tune_id=1" \
          -F tune[title]="my portrait" \
          -F tune[branch]="fast" \
          -F tune[name]=man \
          -F tune[token]=sks \
          -F "tune[prompts_attributes][0][text]=sks man on space circa 1979 on cover of time magazine" \
          -F tune[prompts_attributes][0][callback]="https://optional-callback-url.com/webhooks/astria?user_id=1&prompt_id=1&tune_id=1" \
          -F "tune[images][][email protected]" \
          -F "tune[images][][email protected]" \
          -F "tune[images][][email protected]" \
          -F "tune[images][][email protected]"
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]="fast" \
          -F tune[name]=cat \
          -F tune[token]=sks \
          -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"
Example with cURL, image_urls and nested prompts with JSON
{
  "tune": {
    "name": "cat",
    "branch": "fast",
    "callback": "https://optional-callback-url.com/to-your-service-when-ready",
    "image_urls": [
      "https://i.imgur.com/HLHBnl9.jpeg",
      "https://i.imgur.com/HLHBnl9.jpeg",
      "https://i.imgur.com/HLHBnl9.jpeg",
      "https://i.imgur.com/HLHBnl9.jpeg"
    ],
    "title": "grumpy cat with prompts",
    "prompts_attributes": [
      {
        "text": "sks cat in space circa 1979 French illustration"
      },
      {
        "text": "sks cat getting into trouble viral meme"
      }
    ]
  }
}
curl -X POST -H"Content-Type: application/json" -H "Authorization: Bearer $API_KEY" --data @prompt.json https://api.astria.ai/tunes

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

The below attributes are optional:

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.

ar Aspect-Ratio. 1:1, portrait, 16:9, landscape, anamorphic

num_images Number of images to generate. Values: 2, 4, 8

super_resolution - Boolean. X4 super-resolution.

hires_fix - Boolean. Super resolution details. Available only when super_resolution is true. Adds details.

face_correct - Boolean. Runs another AI model on top to correct the face in the image.

use_lpw - Boolean. Use weighted prompts.

w - width - In multiples of 8. Up until 768.

h - height - In multiples of 8. Up until 768.

ControlNet parameters:

controlnet - BETA. Requires input_image. Possible values: lineart, canny, depth, mlsd, hed.

denoising_strength - BETA.

controlnet_conditioning_scale - BETA.

input_image - BETA. Binary multi-part request with the image. Used in conjunction with controlnet parameter.

input_image_url - BETA. URL to an image. Used in conjunction with controlnet parameter.

Note that you can control `cfg_scale`, `seed`, `steps` as well, however Astria 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[super_resolution]=true \
          -F prompt[face_correct]=true \
          -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...]