> ## Documentation Index
> Fetch the complete documentation index at: https://apidoc.deerapi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Edit

> Use DeerAPI to call the Edit endpoint with request details, response details, examples, and an OpenAPI playground.

## Overview

Use this endpoint to call the Edit workflow through DeerAPI. The API reference on this page shows the request schema, response schema, authentication requirements, and runnable examples for the configured endpoint.

## Before you start

Use the DeerAPI base URL and pass your API Key in the `Authorization` header:

```text theme={null}
https://api.deerapi.com
```

```text theme={null}
Authorization: Bearer $DEERAPI_KEY
```

## Model selection

Choose a current model ID from the [live pricing page](https://api.deerapi.com/pricing). Model availability changes over time, so avoid copying a model ID from an old project without checking the live list first.

## Implementation notes

* Use the OpenAPI playground for the exact request fields accepted by this endpoint.
* Keep API Keys on the server side when you build production applications.
* Log the request ID from failed calls so support can investigate the request.
* Retry `429`, `500`, and `503` responses with exponential backoff.


## OpenAPI

````yaml /api/openapi/image/openai/post-image-edit.openapi.json POST /v1/images/edits
openapi: 3.1.0
info:
  title: Image Editing API
  version: 1.0.0
  description: >-
    Edit existing images through the OpenAI-compatible DeerAPI image edits
    route. GPT image edit models return inline base64 payloads in
    `data[].b64_json`, and `output_format` controls the encoded image type.
servers:
  - url: https://api.deerapi.com
security:
  - bearerAuth: []
paths:
  /v1/images/edits:
    post:
      summary: Edit images
      description: >-
        Upload one or more source images, optionally include a mask, and request
        an edited result with a text instruction.
      operationId: image_editing
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              required:
                - image
                - prompt
              properties:
                image:
                  type: string
                  format: binary
                  description: >-
                    Source image file. Start with one PNG or JPG input for the
                    simplest flow.
                prompt:
                  type: string
                  description: Edit instruction describing the change you want.
                  example: Add a small red ribbon to the paper boat.
                model:
                  type: string
                  description: >-
                    The image editing model to use. Choose a supported model
                    from the [Models page](https://api.deerapi.com/pricing).
                  default: gpt-image-2
                mask:
                  type: string
                  format: binary
                  description: >-
                    Optional PNG mask. Transparent areas indicate regions that
                    should be edited.
                'n':
                  type: string
                  description: Number of edited images to return.
                  default: '1'
                quality:
                  type: string
                  enum:
                    - high
                    - medium
                    - low
                  description: Quality setting for models that support it.
                response_format:
                  type: string
                  enum:
                    - url
                    - b64_json
                  description: >-
                    Requested response container when supported by the selected
                    model. GPT image edit models return `data[].b64_json`; use
                    `output_format` to choose the encoded image type.
                output_format:
                  type: string
                  description: >-
                    Encoded image type for GPT image edit results returned in
                    `data[].b64_json`. For example, use `jpeg` for a JPEG
                    payload.
                  example: jpeg
                size:
                  type: string
                  description: Requested output size when supported by the selected model.
              default:
                model: gpt-image-2
                prompt: Add a small red ribbon to the paper boat.
                output_format: jpeg
            example:
              prompt: Add a small red ribbon to the paper boat.
              model: gpt-image-2
              response_format: json
              image: '@/path/to/image.png'
            examples:
              Default:
                summary: Default request
                value:
                  prompt: Add a small red ribbon to the paper boat.
                  model: gpt-image-2
                  response_format: json
                  image: '@/path/to/image.png'
      responses:
        '200':
          description: Edited image result.
          content:
            application/json:
              schema:
                type: object
                required:
                  - created
                  - data
                  - usage
                properties:
                  created:
                    type: integer
                  usage:
                    type: object
                    properties:
                      prompt_tokens:
                        type: integer
                      completion_tokens:
                        type: integer
                      total_tokens:
                        type: integer
                      prompt_tokens_details:
                        type: object
                        properties:
                          cached_tokens_details:
                            type: object
                            properties: {}
                      completion_tokens_details:
                        type: object
                        properties: {}
                      input_tokens:
                        type: integer
                      output_tokens:
                        type: integer
                      input_tokens_details:
                        type: object
                        properties:
                          image_tokens:
                            type: integer
                          text_tokens:
                            type: integer
                          cached_tokens_details:
                            type: object
                            properties: {}
                      claude_cache_creation_5_m_tokens:
                        type: integer
                      claude_cache_creation_1_h_tokens:
                        type: integer
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        b64_json:
                          type: string
                          description: >-
                            Base64-encoded image payload. Decode this value to
                            get the edited image bytes.
                        url:
                          type: string
                          description: >-
                            Temporary image URL when the selected model supports
                            URL output.
                        revised_prompt:
                          type: string
                          description: Provider-rewritten prompt, when available.
                example:
                  created: 1776836647
                  usage:
                    prompt_tokens: 0
                    completion_tokens: 0
                    total_tokens: 981
                    prompt_tokens_details:
                      cached_tokens_details: {}
                    completion_tokens_details: {}
                    input_tokens: 785
                    output_tokens: 196
                    input_tokens_details:
                      image_tokens: 768
                      text_tokens: 17
                      cached_tokens_details: {}
                    claude_cache_creation_5_m_tokens: 0
                    claude_cache_creation_1_h_tokens: 0
                  data:
                    - b64_json: <base64-image-data>
      x-codeSamples:
        - lang: Shell
          label: cURL
          source: |
            curl -s 'https://api.deerapi.com/v1/images/edits' \
              -H "Authorization: Bearer $DEERAPI_KEY" \
              -F 'prompt=Add a small red ribbon to the paper boat.' \
              -F 'model=gpt-image-2' \
              -F 'response_format=json' \
              -F 'image=@/path/to/image.png'
        - lang: Python
          label: requests
          source: >
            import os

            import requests


            url = "https://api.deerapi.com/v1/images/edits"

            headers = {"Authorization": "Bearer " + os.environ["DEERAPI_KEY"]}

            data = {
              "prompt": "Add a small red ribbon to the paper boat.",
              "model": "gpt-image-2",
              "response_format": "json"
            }

            files = {"image": open("/path/to/image.png", "rb")}


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

            print(response.json())
        - lang: JavaScript
          label: fetch
          source: >
            const form = new FormData();

            form.append("prompt", "Add a small red ribbon to the paper boat.");

            form.append("model", "gpt-image-2");

            form.append("response_format", "json");

            form.append("image", new Blob(["replace with file bytes"]),
            "image.png");


            const response = await
            fetch("https://api.deerapi.com/v1/images/edits", {
              method: "POST",
              headers: { Authorization: `Bearer ${process.env.DEERAPI_KEY}` },
              body: form,
            });


            console.log(await response.json());
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Use a DeerAPI API Key as a Bearer token.

````