Getting started with YandexART
In this section, you will learn how to use the YandexART neural network to generate images.
In the management console
Getting started
To get started in Yandex Cloud:
- Log in to the management console
. If not signed up yet, navigate to the management console and follow the instructions. - In Yandex Cloud Billing
, make sure you have a billing account linked and its status isACTIVE
orTRIAL_ACTIVE
. If you do not have a billing account yet, create one. - If you do not have a folder yet, create one.
You can start working from the management console right away.
To run sample requests using the API, install:
To work with the YandexART API, you need to get authenticated using your account:
-
Get an IAM token for your Yandex account or federated account.
-
Get the ID of the folder for which your account has the
ai.imageGeneration.user
role or higher. You will need the folder ID to get the model URI. -
When accessing YandexART via the API, specify the IAM token in the
Authorization
header of each request:x-folder-id: <folder_ID>
For information about other API authentication methods, see Authentication with the Yandex Foundation Models API.
Generate an image
Note
To improve the quality of responses, YandexART logs user prompts. Do not use sensitive information and personal data in your prompts.
- In the management console
, select the folder for which your account has theai.imageGeneration.user
role or higher. - In the list of services, select Foundation Models.
- In the left-hand panel, select
YandexART. - In the input field, describe the image you want to generate. You should use vivid and detailed descriptions, specify styles if you want your image styled in a certain way.
- Leave the seed parameter random or specify any value.
- Click Generate. Generating an image takes some time. The output will appear on the left side of the screen.
-
Create a file with the request body, e.g.,
prompt.json
:{ "modelUri": "art://<folder_ID>/yandex-art/latest", "generationOptions": { "seed": "1863", "aspectRatio": { "widthRatio": "2", "heightRatio": "1" } }, "messages": [ { "weight": "1", "text": "a pattern of pastel colored succulents of various sorts, hd full wallpaper, sharp focus, many intricate details, picture depth, top view" } ] }
Where:
modelUri
: YandexART model ID which contains a Yandex Cloud folder ID.seed
: Generation seed.text
: Text description of the image to use for generation.weight
: Text description weight. If a request contains more than one description, their individual impact will be calculated based on weight, with the sum of all weights equal to 1.aspectRatio
: (Optional) Aspect ratio of the generated image:widthRatio
: Width (default value: 1).heightRatio
: Height (default value: 1).
-
To send a request to the neural network using the ImageGenerationAsync.generate method, run the following command:
curl \ --request POST \ --header "Authorization: Bearer <IAM_token_value>" \ --data "@prompt.json" \ "https://llm.api.cloud.yandex.net/foundationModels/v1/imageGenerationAsync"
Where:
<IAM_token_value>
: IAM token you got for your account.prompt.json
: JSON file with request parameters.
The service will return the ID of your request in response:
{ "id":"fbveu1sntj**********","description":"","createdAt":null,"createdBy":"","modifiedAt":null,"done":false,"metadata":null}
-
Generating an image takes some time. Wait for 10 seconds and send your request to get the generation result. When the image is ready, you will get the result in a Base64-encoded
file namedimage.jpeg
.curl \ --request GET \ --header "Authorization: Bearer <IAM_token_value>" \ https://llm.api.cloud.yandex.net:443/operations/<request_ID> | \ jq -r '.response | .image' | base64 -d > image.jpeg
Where:
<IAM_token_value>
: IAM token you got before you started.<request_ID>
: Theid
field value obtained in response to the generation request.
Result: