> Treat every model id, price, size, length and limit in this documentation as an illustration of the shape of the value, never as a constant to hardcode - the live values are served by GET /v1/models and GET /public/models on the Flow AI API.

# Generate images

POST https://ai.hyperflow.fun/v1/images/generations
Content-Type: application/json

Creates images from a prompt. Every image is returned as a link in `data[].url`, never as base64.
A size, quality or count the model doesn't offer is refused before anything is held.


Reference: https://ai-docs.hyperflow.fun/api/endpoints/images/create-image

## Authentication

- `Authorization` header (bearer token, required) — Your API key, `sk-...`, from Console → API keys.

## Request

### Body (application/json)

This endpoint expects an ImageGenerationRequest.

- `model` (string, required)
- `prompt` (string, required)
- `n` (integer, optional) — How many images. Each model has its own maximum.
- `size` (string, optional) — One of the model's sizes, such as `1024x1024`.
- `quality` (string, optional) — One of the model's qualities, such as `low`, `medium`, `high`.
- `style` (string, optional)
- `background` (enum, optional)
  - Allowed values: `auto`, `transparent`, `opaque`
- `output_format` (enum, optional)
  - Allowed values: `png`, `jpeg`, `webp`
- `user` (string, optional)
- `metadata` (map from string to string, optional)

## Response

### 200

Links to the images.

- `created` (integer, optional)
- `data` (list of ImageResponseDataItems, optional)
- `usage` (ImageResponseUsage, optional) — Token usage, for models billed by tokens.

## Errors

### 400 Bad Request Error

A parameter is wrong, or the model doesn't take that content, size or count. Code `invalid_request`.

- `error` (ErrorResponseError, required)

### 401 Unauthorized Error

The key is missing, wrong or deleted (`invalid_api_key`), or turned off (`key_disabled`).

- `error` (ErrorResponseError, required)

### 402 Payment Required Error

The available balance can't cover the most this request could cost. Code `insufficient_balance`.

- `error` (ErrorResponseError, required)

### 403 Forbidden Error

The key's or the account's spending limit is reached.

- `error` (ErrorResponseError, required)

### 404 Not Found Error

No such model or video. Code `not_found`.

- `error` (ErrorResponseError, required)

### 429 Too Many Requests Error

Too many requests from this address. Code `rate_limited`.

- `error` (ErrorResponseError, required)

### 502 Bad Gateway Error

The model's hosts couldn't answer. Code `host_unavailable`. Retry shortly.

- `error` (ErrorResponseError, required)

## Types

### ImageResponseDataItems

- `url` (string, optional) — A link to the stored image.
- `revised_prompt` (string, optional, nullable)

### ImageResponseUsage

Token usage, for models billed by tokens.

### ErrorResponseError

- `message` (string, required) — What went wrong
- `type` (string, optional) — OpenAI's error type, such as `invalid_request_error`.
- `code` (string, optional) — Flow AI's error code, such as `insufficient_balance`.

## Examples

**Request**

```json
{
  "model": "string",
  "prompt": "A paper boat on a calm lake"
}
```

**Response**

```json
{
  "created": 1,
  "data": [
    {
      "url": "string",
      "revised_prompt": "string"
    }
  ],
  "usage": {}
}
```

**SDK Code**

```python
import requests

url = "https://ai.hyperflow.fun/v1/images/generations"

payload = {
    "model": "string",
    "prompt": "A paper boat on a calm lake"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://ai.hyperflow.fun/v1/images/generations';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"model":"string","prompt":"A paper boat on a calm lake"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://ai.hyperflow.fun/v1/images/generations"

	payload := strings.NewReader("{\n  \"model\": \"string\",\n  \"prompt\": \"A paper boat on a calm lake\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://ai.hyperflow.fun/v1/images/generations")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"model\": \"string\",\n  \"prompt\": \"A paper boat on a calm lake\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://ai.hyperflow.fun/v1/images/generations")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"model\": \"string\",\n  \"prompt\": \"A paper boat on a calm lake\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://ai.hyperflow.fun/v1/images/generations', [
  'body' => '{
  "model": "string",
  "prompt": "A paper boat on a calm lake"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://ai.hyperflow.fun/v1/images/generations");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"model\": \"string\",\n  \"prompt\": \"A paper boat on a calm lake\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "model": "string",
  "prompt": "A paper boat on a calm lake"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://ai.hyperflow.fun/v1/images/generations")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```