# Using the API

## Start an image generation job

1. Generate an API key on [dreamlook.ai/api-keys](https://dreamlook.ai/api-keys). Treat this key like a password: keep it safe, and don't expose it publicly!
2. Export your API key as the environment variable `DREAMLOOK_API_KEY` :

```sh
export DREAMLOOK_API_KEY="dl-YOURKEYHERE"
```

3. Go to <https://dreamlook.ai/image-gen> and configure your generation parameters as described in [using-the-website](https://docs.dreamlook.ai/generate-images/using-the-website "mention")
4. Copy the content of "API request" and paste it into a terminal. Running the command will trigger a new generation job:

<div data-full-width="true"><figure><img src="https://3775798052-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbjzMS9bi5lfz4h6oo4EA%2Fuploads%2FKqyx8QBcQWiNcpVg6wrm%2FScreenshot%202023-06-29%20at%2021.37.06.png?alt=media&#x26;token=1bf93c36-8ff1-4d0b-a359-4565ab746ef5" alt=""><figcaption></figcaption></figure></div>

5. You will get a unique job ID as a response:

```
{
    "job_id":"ig_63d83f95"
}
```

Jobs created from the API are also visible from the website, so you can check <https://dreamlook.ai/jobs/image-gen> to see how your job is progressing.

## Keeping track of your jobs

Check the documentation in [using-the-api](https://docs.dreamlook.ai/train-models/using-the-api "mention") to see how to list your jobs and check their state. Image generation jobs have the job type `image-gen`.

Here's an example of a image generation job response:

```json
{
    "job_type": "image-gen",
    "job_id": "ig_90c7ebd5",
    "state": "success",
    "state_updated": "2023-06-29T16:28:31.317874",
    "state_running_start": "2023-06-29T16:27:39.284893",
    "state_running_end": "2023-06-29T16:28:31.317874",
    "state_queued_start": "2023-06-29T16:25:28.018608",
    "state_queued_end": "2023-06-29T16:27:39.284893",
    "queued_duration": 131.266285,
    "running_duration": 52.032981,
    "queueing_state": "default",
    "config": {
        "prompt": "portrait photo of ukj man, color, Martin Schoeller, serious eyes, perfect eyes, cinematic, 80mm portrait photography, dramatic lighting photography, national geographic, portrait, photo, photography, Stoic, cinematic, 4k, epic, detailed photograph, shot on kodak detailed, bokeh, cinematic, hbo, dark moody, volumetric fog",
        "negative_prompt": "nudity, amputee, bad anatomy, blurry, fuzzy, disfigured, misshaped, mutant, deformed, bad art, out of frame, off center",
        "width": 768,
        "height": 1024,
        "num_samples": 16,
        "checkpoint_id": "ckp_15f9112b",
        "model_type": "sd-v1",
        "base_model": null,
        "num_inference_steps": 20,
        "scheduler_type": "dpm++",
        "enable_hrf": true,
        "denoising_strength": 0.6,
        "seed": -1
    },
    "dreambooth_result": null,
    "image_gen_results": [
        {
            "checkpoint_id": "ckp_15f9112b",
            "config_idx": 0,
            "generated_images": [
                {
                    "generated_image_id": "c7102f3f",
                    "url": "https://storage.googleapis.com/nyxai-standard-usc2/images/generated_images/ig_90c7ebc5/ig_90c7ebc5_c7102f3f.png",
                    "seed": 2811570194,
                    "generation_idx": 0
                },
                {
                    "generated_image_id": "577ab3c6",
                    "url": "https://storage.googleapis.com/nyxai-standard-usc2/images/generated_images/ig_90c7ebc5/ig_90c7ebc5_577ab3c6.png",
                    "seed": 1587936907,
                    "generation_idx": 2
                },
                ...
            ]
        }
    ],
    "percentage_done": 100,
    "failure_reason": null,
    "failure_reason_data": null,
    "thumbnails": [
        "https://storage.googleapis.com/nyxai-public-usc2/images/thumbnails/ig_90c7ebc5/ig_90c7ebc5_c7102f3f_thumbnail.png",
        "https://storage.googleapis.com/nyxai-public-usc2/images/thumbnails/ig_90c7ebc5/ig_90c7ebc5_3ef6b3fc_thumbnail.png",
        "https://storage.googleapis.com/nyxai-public-usc2/images/thumbnails/ig_90c7ebc5/ig_90c7ebc5_732c4f70_thumbnail.png",
        "https://storage.googleapis.com/nyxai-public-usc2/images/thumbnails/ig_90c7ebc5/ig_90c7ebc5_93c5e4d0_thumbnail.png"
    ],
    "tags": []
}
```
