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.
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.
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
.
Community SDKs
Aaron Brand published a Python client for the API:
Python SDKA gist for how to set up Bubble.io with multi-part request
Setting up Bubble.ioTune 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.
Note this request is a multi-part encoded form request, i.e: not JSON
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]', 'zwx');
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())
}
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]=zwx \
-F "tune[prompts_attributes][0][text]=zwx 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][]=@1.jpg" \
-F "tune[images][]=@2.jpg" \
-F "tune[images][]=@3.jpg" \
-F "tune[images][]=@4.jpg"
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]=zwx \
-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"
{
"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"
],
"title": "grumpy cat with prompts",
"prompts_attributes": [
{
"text": "zwx cat in space circa 1979 French illustration"
},
{
"text": "zwx 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
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. Possible values: 1:1
, portrait
, 16:9
, landscape
, anamorphic
num_images
Number of images to generate. Possible values: 4
, 8
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 zwx 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 zwx 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...]