> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs-staging.joytokens.ai/llms.txt.

# Image Edits

POST https://api-staging.joytokens.ai/openai/v1/images/edits
Content-Type: application/json

Edits one or more source images according to a text prompt using an OpenAI-compatible request. Unlike the OpenAI edits endpoint, JoyToken accepts a JSON body (not multipart/form-data): prompt and image are required, where image is either a single string or an array of strings. Each image may be an http(s) URL or a base64 data URI (data:\<mime>;base64,\<data>). When a URL is provided, JoyToken downloads it and converts it to a data URI before forwarding to the selected provider. JoyToken forwards supported image options and appends routing and billing details under metadata. This endpoint is non-streaming: do not send stream: true. JoyToken returns one application/json response after editing completes and never emits SSE events or \[DONE].

Output format: by default JoyToken returns each edited image as a base64 payload in `data[].b64_json`. To render it, prefix it as a data URI, e.g. `img.src = "data:image/png;base64," + resp.data[0].b64_json`. If you prefer a hosted image URL instead of base64, send `response_format: url`; JoyToken then returns `data[].url` when every eligible image model supports URL output, and otherwise falls back to `b64_json`. There is no built-in base64-to-URL conversion: if you must have a URL, either request `response_format: url` (subject to model support) or upload the returned base64 to your own object storage and use that URL.

Reference: https://docs-staging.joytokens.ai/open-api/api-reference/compatible-model-ap-is/images/edit-image

## Authentication

- `Authorization` header (bearer token, required) — Use `Authorization: Bearer $JOY_TOKEN_API_KEY`.

## Request

### Headers

- `X-Request-ID` (string, optional) — Optional request identifier for deduplication, billing, logs, and debugging correlation.

### Body (application/json)

This endpoint expects an ImageEditRequest.

- `prompt` (string, required) — Text instruction describing how to edit the source image(s).
- `image` (ImageEditRequestImage, required) — Source image(s) to edit. A single string edits one image; an array of strings edits multiple images. Each value is either an http(s) URL or a base64 data URI (data:\<mime>;base64,\<data>). Empty string, empty array, and null are treated as missing and return 400.
- `model` (string, optional) — Use `auto` to let the gateway pick the image model, or pass a concrete `modelName` from the model catalog to pin that model. Both ways are available to every account.
- `n` (integer, optional) — Number of images to generate. Provider limits vary.
- `size` (string, optional) — Provider-supported output dimensions, for example 1024x1024.
- `user` (string, optional) — Optional end-user identifier.
- `response_format` (enum, optional) — Output mode. Defaults to `b64_json` (base64 in `data[].b64_json`). Set `url` to receive a hosted image URL in `data[].url` instead; this only works when every eligible image model supports URL output, otherwise JoyToken falls back to `b64_json`. Omit unless you specifically need URL output.
  - Allowed values: `url`, `b64_json`

## Response

### 200

Successful non-streaming image edit result returned as one application/json document.

- `data` (list of GeneratedImage, required)
- `created` (long, optional) — Unix timestamp for the generation result.
- `metadata` (JoyTokenMetadata, optional) — JoyToken routing and billing metadata appended by the gateway when available. In orchestration (multi-task planning) mode this object also carries per-task identifiers, and the response returns one metadata object per task.

## Errors

### 400 Bad Request Error

Invalid JSON, missing prompt or image, malformed data URI, or image download/convert failure.

- `error` (ErrorResponseError, required)

### 401 Unauthorized Error

Missing, invalid, revoked, or expired API key.

- `error` (ErrorResponseError, required)

### 402 Payment Required Error

Insufficient wallet balance or billing freeze failure.

- `error` (ErrorResponseError, required)

### 403 Forbidden Error

Request blocked by API key policy, IP policy, model blacklist, or route strategy.

- `error` (ErrorResponseError, required)

### 409 Conflict Error

Duplicate X-Request-ID within the deduplication window.

- `error` (ErrorResponseError, required)

### 413 Content Too Large Error

Request body exceeds the 8MB limit.

- `error` (ErrorResponseError, required)

### 429 Too Many Requests Error

Rate limit exceeded.

- `error` (ErrorResponseError, required)

### 500 Internal Server Error

Internal gateway or provider error.

- `error` (ErrorResponseError, required)

## Types

### ImageEditRequestImage

Source image(s) to edit. A single string edits one image; an array of strings edits multiple images. Each value is either an http(s) URL or a base64 data URI (data:\<mime>;base64,\<data>). Empty string, empty array, and null are treated as missing and return 400.

- string
- list of string

### GeneratedImage

- `url` (string, optional) — URL for the generated image when response_format is url.
- `b64_json` (string, optional) — Base64-encoded image data when response_format is b64_json.
- `revised_prompt` (string, optional) — Provider-revised prompt, when returned.

### JoyTokenMetadata

JoyToken routing and billing metadata appended by the gateway when available. In orchestration (multi-task planning) mode this object also carries per-task identifiers, and the response returns one metadata object per task.

- `model` (string, optional) — Final model used. May be `auto` for aggregation tasks, or a concrete sub-model (for example `Gemini-3-Flash-Preview`, `gpt-5.6-luna`) that executed a specific task.
- `tier` (enum, optional) — JoyToken model tier.
  - Allowed values: `economy`, `standard`, `premium`
- `score` (double, optional)
- `billing_id` (string, optional) — Billing account identifier. Present in orchestration metadata events.
- `tag` (list of string, optional) — Role tags describing what a task did. Present in orchestration mode. Common values include orchestration, search, reasoning, writing, and aggregation.
- `task_id` (string, optional) — Task identifier. Reserved values are `__planner__` and `__final__`.
- `task_seq` (integer, optional) — Execution sequence of the task. `0` is the planner.
- `task_status` (enum, optional) — Task lifecycle status.
  - Allowed values: `DONE`
- `title` (string, optional) — Human-readable task title from the plan.
- `billing` (JoyTokenMetadataBilling, optional)
- `usage` (map from string to any, optional) — Provider usage plus JoyToken credits_used when available.
- `latency` (JoyTokenMetadataLatency, optional) — Latency breakdown. Orchestration tasks report first_token_ms and stream_ms.
- `request_id` (string, optional) — Gateway request identifier for log, billing, and debugging correlation. Present on non-streaming top-level metadata.
- `model_recommendation` (JoyTokenMetadataModelRecommendation, optional) — Router's model recommendation for this request, including candidate models and their scores.
- `task_score` (JoyTokenMetadataTaskScore, optional) — Router scoring breakdown used to select the model.

### ErrorResponseError

- `message` (string, required)
- `type` (string, optional)
- `code` (ErrorResponseErrorCode, optional, nullable)

### JoyTokenMetadataBilling

- `credits_used` (string, optional)
- `input_tokens` (integer, optional)
- `output_tokens` (integer, optional)
- `cached_input_tokens` (integer, optional)
- `cached_output_tokens` (integer, optional)

### JoyTokenMetadataLatency

Latency breakdown. Orchestration tasks report first_token_ms and stream_ms.

- `routing_ms` (integer, optional)
- `first_token_ms` (integer, optional)
- `stream_ms` (integer, optional)

### JoyTokenMetadataModelRecommendation

Router's model recommendation for this request, including candidate models and their scores.

- `models` (list of JoyTokenMetadataModelRecommendationModelsItems, optional)

### JoyTokenMetadataTaskScore

Router scoring breakdown used to select the model.

- `history_score` (double, optional)
- `latest_conversation_score` (double, optional)
- `multimodal_score` (double, optional)
- `system_score` (double, optional)
- `tool_score` (double, optional)
- `total_score` (double, optional)

### ErrorResponseErrorCode

- string
- integer

### JoyTokenMetadataModelRecommendationModelsItems

- `model_id` (string, optional)
- `probability` (double, optional)
- `selected` (boolean, optional)
- `feature_tags` (list of string, optional)

## Examples

### Images_editImage_example

**Response**

```json
{
  "data": [
    {
      "b64_json": "iVBORw0KGgoAAAANSUhEUgAA..."
    }
  ],
  "created": 1793395200,
  "metadata": {
    "model": "auto",
    "tier": "standard",
    "billing": {
      "credits_used": "12.34"
    },
    "usage": {
      "credits_used": "12.34",
      "image_input_tokens": 0,
      "image_output_tokens": 1290,
      "text_input_tokens": 25
    }
  }
}
```

**SDK Code**

```python Images_editImage_example
import requests

url = "https://api-staging.joytokens.ai/openai/v1/images/edits"

headers = {"Authorization": "Bearer <token>"}

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

print(response.json())
```

```javascript Images_editImage_example
const url = 'https://api-staging.joytokens.ai/openai/v1/images/edits';
const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};

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

```go Images_editImage_example
package main

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

func main() {

	url := "https://api-staging.joytokens.ai/openai/v1/images/edits"

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

	req.Header.Add("Authorization", "Bearer <token>")

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

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

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

}
```

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

url = URI("https://api-staging.joytokens.ai/openai/v1/images/edits")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'

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

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

HttpResponse<String> response = Unirest.post("https://api-staging.joytokens.ai/openai/v1/images/edits")
  .header("Authorization", "Bearer <token>")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api-staging.joytokens.ai/openai/v1/images/edits', [
  'headers' => [
    'Authorization' => 'Bearer <token>',
  ],
]);

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

```csharp Images_editImage_example
using RestSharp;

var client = new RestClient("https://api-staging.joytokens.ai/openai/v1/images/edits");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
IRestResponse response = client.Execute(request);
```

```swift Images_editImage_example
import Foundation

let headers = ["Authorization": "Bearer <token>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://api-staging.joytokens.ai/openai/v1/images/edits")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers

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()
```

### Single image via URL

**Request**

```json
{
  "prompt": "Replace the background with a starry sky and keep the subject unchanged",
  "image": "https://picsum.photos/512/512",
  "model": "auto",
  "n": 1,
  "size": "1024x1024"
}
```

**Response**

```json
{
  "data": [
    {
      "b64_json": "iVBORw0KGgoAAAANSUhEUgAA..."
    }
  ],
  "created": 1793395200,
  "metadata": {
    "model": "auto",
    "tier": "standard",
    "billing": {
      "credits_used": "12.34"
    },
    "usage": {
      "credits_used": "12.34",
      "image_input_tokens": 0,
      "image_output_tokens": 1290,
      "text_input_tokens": 25
    }
  }
}
```

**SDK Code**

```python Single image via URL
import requests

url = "https://api-staging.joytokens.ai/openai/v1/images/edits"

payload = {
    "prompt": "Replace the background with a starry sky and keep the subject unchanged",
    "image": "https://picsum.photos/512/512",
    "model": "auto",
    "n": 1,
    "size": "1024x1024"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Single image via URL
const url = 'https://api-staging.joytokens.ai/openai/v1/images/edits';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"prompt":"Replace the background with a starry sky and keep the subject unchanged","image":"https://picsum.photos/512/512","model":"auto","n":1,"size":"1024x1024"}'
};

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

```go Single image via URL
package main

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

func main() {

	url := "https://api-staging.joytokens.ai/openai/v1/images/edits"

	payload := strings.NewReader("{\n  \"prompt\": \"Replace the background with a starry sky and keep the subject unchanged\",\n  \"image\": \"https://picsum.photos/512/512\",\n  \"model\": \"auto\",\n  \"n\": 1,\n  \"size\": \"1024x1024\"\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 Single image via URL
require 'uri'
require 'net/http'

url = URI("https://api-staging.joytokens.ai/openai/v1/images/edits")

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  \"prompt\": \"Replace the background with a starry sky and keep the subject unchanged\",\n  \"image\": \"https://picsum.photos/512/512\",\n  \"model\": \"auto\",\n  \"n\": 1,\n  \"size\": \"1024x1024\"\n}"

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

```java Single image via URL
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api-staging.joytokens.ai/openai/v1/images/edits")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"prompt\": \"Replace the background with a starry sky and keep the subject unchanged\",\n  \"image\": \"https://picsum.photos/512/512\",\n  \"model\": \"auto\",\n  \"n\": 1,\n  \"size\": \"1024x1024\"\n}")
  .asString();
```

```php Single image via URL
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api-staging.joytokens.ai/openai/v1/images/edits', [
  'body' => '{
  "prompt": "Replace the background with a starry sky and keep the subject unchanged",
  "image": "https://picsum.photos/512/512",
  "model": "auto",
  "n": 1,
  "size": "1024x1024"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp Single image via URL
using RestSharp;

var client = new RestClient("https://api-staging.joytokens.ai/openai/v1/images/edits");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"prompt\": \"Replace the background with a starry sky and keep the subject unchanged\",\n  \"image\": \"https://picsum.photos/512/512\",\n  \"model\": \"auto\",\n  \"n\": 1,\n  \"size\": \"1024x1024\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Single image via URL
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "prompt": "Replace the background with a starry sky and keep the subject unchanged",
  "image": "https://picsum.photos/512/512",
  "model": "auto",
  "n": 1,
  "size": "1024x1024"
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api-staging.joytokens.ai/openai/v1/images/edits")! 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()
```

### Ask for a hosted URL instead of base64

**Request**

```json
{
  "prompt": "Replace the background with a starry sky and keep the subject unchanged",
  "image": "https://picsum.photos/512/512",
  "model": "auto",
  "n": 1,
  "size": "1024x1024",
  "response_format": "url"
}
```

**Response**

```json
{
  "data": [
    {
      "b64_json": "iVBORw0KGgoAAAANSUhEUgAA..."
    }
  ],
  "created": 1793395200,
  "metadata": {
    "model": "auto",
    "tier": "standard",
    "billing": {
      "credits_used": "12.34"
    },
    "usage": {
      "credits_used": "12.34",
      "image_input_tokens": 0,
      "image_output_tokens": 1290,
      "text_input_tokens": 25
    }
  }
}
```

**SDK Code**

```python Ask for a hosted URL instead of base64
import requests

url = "https://api-staging.joytokens.ai/openai/v1/images/edits"

payload = {
    "prompt": "Replace the background with a starry sky and keep the subject unchanged",
    "image": "https://picsum.photos/512/512",
    "model": "auto",
    "n": 1,
    "size": "1024x1024",
    "response_format": "url"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Ask for a hosted URL instead of base64
const url = 'https://api-staging.joytokens.ai/openai/v1/images/edits';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"prompt":"Replace the background with a starry sky and keep the subject unchanged","image":"https://picsum.photos/512/512","model":"auto","n":1,"size":"1024x1024","response_format":"url"}'
};

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

```go Ask for a hosted URL instead of base64
package main

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

func main() {

	url := "https://api-staging.joytokens.ai/openai/v1/images/edits"

	payload := strings.NewReader("{\n  \"prompt\": \"Replace the background with a starry sky and keep the subject unchanged\",\n  \"image\": \"https://picsum.photos/512/512\",\n  \"model\": \"auto\",\n  \"n\": 1,\n  \"size\": \"1024x1024\",\n  \"response_format\": \"url\"\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 Ask for a hosted URL instead of base64
require 'uri'
require 'net/http'

url = URI("https://api-staging.joytokens.ai/openai/v1/images/edits")

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  \"prompt\": \"Replace the background with a starry sky and keep the subject unchanged\",\n  \"image\": \"https://picsum.photos/512/512\",\n  \"model\": \"auto\",\n  \"n\": 1,\n  \"size\": \"1024x1024\",\n  \"response_format\": \"url\"\n}"

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

```java Ask for a hosted URL instead of base64
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api-staging.joytokens.ai/openai/v1/images/edits")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"prompt\": \"Replace the background with a starry sky and keep the subject unchanged\",\n  \"image\": \"https://picsum.photos/512/512\",\n  \"model\": \"auto\",\n  \"n\": 1,\n  \"size\": \"1024x1024\",\n  \"response_format\": \"url\"\n}")
  .asString();
```

```php Ask for a hosted URL instead of base64
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api-staging.joytokens.ai/openai/v1/images/edits', [
  'body' => '{
  "prompt": "Replace the background with a starry sky and keep the subject unchanged",
  "image": "https://picsum.photos/512/512",
  "model": "auto",
  "n": 1,
  "size": "1024x1024",
  "response_format": "url"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp Ask for a hosted URL instead of base64
using RestSharp;

var client = new RestClient("https://api-staging.joytokens.ai/openai/v1/images/edits");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"prompt\": \"Replace the background with a starry sky and keep the subject unchanged\",\n  \"image\": \"https://picsum.photos/512/512\",\n  \"model\": \"auto\",\n  \"n\": 1,\n  \"size\": \"1024x1024\",\n  \"response_format\": \"url\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Ask for a hosted URL instead of base64
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "prompt": "Replace the background with a starry sky and keep the subject unchanged",
  "image": "https://picsum.photos/512/512",
  "model": "auto",
  "n": 1,
  "size": "1024x1024",
  "response_format": "url"
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api-staging.joytokens.ai/openai/v1/images/edits")! 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()
```

### Single image via base64 data URI

**Request**

```json
{
  "prompt": "Add a red Christmas hat to the person",
  "image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==",
  "model": "auto",
  "n": 1
}
```

**Response**

```json
{
  "data": [
    {
      "b64_json": "iVBORw0KGgoAAAANSUhEUgAA..."
    }
  ],
  "created": 1793395200,
  "metadata": {
    "model": "auto",
    "tier": "standard",
    "billing": {
      "credits_used": "12.34"
    },
    "usage": {
      "credits_used": "12.34",
      "image_input_tokens": 0,
      "image_output_tokens": 1290,
      "text_input_tokens": 25
    }
  }
}
```

**SDK Code**

```python Single image via base64 data URI
import requests

url = "https://api-staging.joytokens.ai/openai/v1/images/edits"

payload = {
    "prompt": "Add a red Christmas hat to the person",
    "image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==",
    "model": "auto",
    "n": 1
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Single image via base64 data URI
const url = 'https://api-staging.joytokens.ai/openai/v1/images/edits';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"prompt":"Add a red Christmas hat to the person","image":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==","model":"auto","n":1}'
};

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

```go Single image via base64 data URI
package main

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

func main() {

	url := "https://api-staging.joytokens.ai/openai/v1/images/edits"

	payload := strings.NewReader("{\n  \"prompt\": \"Add a red Christmas hat to the person\",\n  \"image\": \"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==\",\n  \"model\": \"auto\",\n  \"n\": 1\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 Single image via base64 data URI
require 'uri'
require 'net/http'

url = URI("https://api-staging.joytokens.ai/openai/v1/images/edits")

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  \"prompt\": \"Add a red Christmas hat to the person\",\n  \"image\": \"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==\",\n  \"model\": \"auto\",\n  \"n\": 1\n}"

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

```java Single image via base64 data URI
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api-staging.joytokens.ai/openai/v1/images/edits")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"prompt\": \"Add a red Christmas hat to the person\",\n  \"image\": \"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==\",\n  \"model\": \"auto\",\n  \"n\": 1\n}")
  .asString();
```

```php Single image via base64 data URI
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api-staging.joytokens.ai/openai/v1/images/edits', [
  'body' => '{
  "prompt": "Add a red Christmas hat to the person",
  "image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==",
  "model": "auto",
  "n": 1
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp Single image via base64 data URI
using RestSharp;

var client = new RestClient("https://api-staging.joytokens.ai/openai/v1/images/edits");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"prompt\": \"Add a red Christmas hat to the person\",\n  \"image\": \"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==\",\n  \"model\": \"auto\",\n  \"n\": 1\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Single image via base64 data URI
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "prompt": "Add a red Christmas hat to the person",
  "image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==",
  "model": "auto",
  "n": 1
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api-staging.joytokens.ai/openai/v1/images/edits")! 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()
```

### Multiple images via array

**Request**

```json
{
  "prompt": "Blend these two images into one poster",
  "image": [
    "https://picsum.photos/512/512",
    "https://picsum.photos/512/512?2"
  ],
  "model": "auto"
}
```

**Response**

```json
{
  "data": [
    {
      "b64_json": "iVBORw0KGgoAAAANSUhEUgAA..."
    }
  ],
  "created": 1793395200,
  "metadata": {
    "model": "auto",
    "tier": "standard",
    "billing": {
      "credits_used": "12.34"
    },
    "usage": {
      "credits_used": "12.34",
      "image_input_tokens": 0,
      "image_output_tokens": 1290,
      "text_input_tokens": 25
    }
  }
}
```

**SDK Code**

```python Multiple images via array
import requests

url = "https://api-staging.joytokens.ai/openai/v1/images/edits"

payload = {
    "prompt": "Blend these two images into one poster",
    "image": ["https://picsum.photos/512/512", "https://picsum.photos/512/512?2"],
    "model": "auto"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Multiple images via array
const url = 'https://api-staging.joytokens.ai/openai/v1/images/edits';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"prompt":"Blend these two images into one poster","image":["https://picsum.photos/512/512","https://picsum.photos/512/512?2"],"model":"auto"}'
};

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

```go Multiple images via array
package main

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

func main() {

	url := "https://api-staging.joytokens.ai/openai/v1/images/edits"

	payload := strings.NewReader("{\n  \"prompt\": \"Blend these two images into one poster\",\n  \"image\": [\n    \"https://picsum.photos/512/512\",\n    \"https://picsum.photos/512/512?2\"\n  ],\n  \"model\": \"auto\"\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 Multiple images via array
require 'uri'
require 'net/http'

url = URI("https://api-staging.joytokens.ai/openai/v1/images/edits")

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  \"prompt\": \"Blend these two images into one poster\",\n  \"image\": [\n    \"https://picsum.photos/512/512\",\n    \"https://picsum.photos/512/512?2\"\n  ],\n  \"model\": \"auto\"\n}"

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

```java Multiple images via array
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api-staging.joytokens.ai/openai/v1/images/edits")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"prompt\": \"Blend these two images into one poster\",\n  \"image\": [\n    \"https://picsum.photos/512/512\",\n    \"https://picsum.photos/512/512?2\"\n  ],\n  \"model\": \"auto\"\n}")
  .asString();
```

```php Multiple images via array
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api-staging.joytokens.ai/openai/v1/images/edits', [
  'body' => '{
  "prompt": "Blend these two images into one poster",
  "image": [
    "https://picsum.photos/512/512",
    "https://picsum.photos/512/512?2"
  ],
  "model": "auto"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp Multiple images via array
using RestSharp;

var client = new RestClient("https://api-staging.joytokens.ai/openai/v1/images/edits");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"prompt\": \"Blend these two images into one poster\",\n  \"image\": [\n    \"https://picsum.photos/512/512\",\n    \"https://picsum.photos/512/512?2\"\n  ],\n  \"model\": \"auto\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Multiple images via array
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "prompt": "Blend these two images into one poster",
  "image": ["https://picsum.photos/512/512", "https://picsum.photos/512/512?2"],
  "model": "auto"
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api-staging.joytokens.ai/openai/v1/images/edits")! 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()
```