openapi: 3.1.0
info:
  title: Car Background AI API
  version: 1.0.0
  summary: Server-to-server API for car photos.
  description: |
    The Car Background AI API replaces the background of a car photo with one
    of the pre-built scenes, returning a high-resolution result image, and
    hides license plates.

    All endpoints are authenticated with a workspace-scoped API key. Generations
    consume one credit per successful call from the workspace's balance.

    Add your logo to generations with the `logo` option: upload up to seven
    logos once with `POST /v1/logos` (the same logos as in the app) or pass
    them inline per request. Pass a list to draw up to seven logos on one
    photo.

    `POST /v1/plates` hides license plates without changing the background. It
    is included with any active subscription (no credits), up to a fair-use
    limit of 2,000 photos per workspace per month.

    AI agents can use the same features through the MCP server at
    `https://api.carbackground.ai/mcp` (sign in with OAuth, or send an API key
    as the Bearer token). See `https://api.carbackground.ai/llms.txt`.

    Rate limit: 80 requests/second per key, surfaced via `X-RateLimit-*` headers;
    a `429` includes `Retry-After`.
  contact:
    email: hello@carbackground.ai
    url: https://carbackground.ai
  license:
    name: Proprietary
    url: https://carbackground.ai/terms

servers:
  - url: https://api.carbackground.ai
    description: Production

security:
  - apiKey: []

tags:
  - name: v1

paths:
  /v1/generations:
    post:
      tags: [v1]
      summary: Generate a background-replaced image
      description: |
        Submit a car photo (by URL or inline base64) and receive an image with
        the chosen background applied. The response returns only once the
        generation completes, typically 30-60s.
      operationId: createGeneration
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/GenerationRequest"
            examples:
              from_url:
                summary: Image fetched from a URL
                value:
                  image_url: https://customer-cdn.example.com/listings/42/hero.jpg
                  background_id: white-panels
              from_base64:
                summary: Inline base64
                value:
                  image_base64: "/9j/4AAQSkZJRgABAQEASABIAAD..."
                  background_id: alpine-lot
              custom_background:
                summary: Workspace custom background (UUID from GET /v1/backgrounds)
                value:
                  image_url: https://customer-cdn.example.com/listings/42/hero.jpg
                  background_id: 3fa85f64-5717-4562-b3fc-2c963f66afa6
              with_logo:
                summary: Workspace logo in the top-left corner, 4:3 output
                value:
                  image_url: https://customer-cdn.example.com/listings/42/hero.jpg
                  background_id: white-panels
                  aspect_ratio: "4:3"
                  logo:
                    id: logo_1792240000000.png
                    position: top-left
              inline_logo:
                summary: Inline logo at an exact position and size
                value:
                  image_url: https://customer-cdn.example.com/listings/42/hero.jpg
                  background_id: white-panels
                  logo:
                    image_url: https://customer-cdn.example.com/brand/dealer-17.png
                    x: 0.05
                    y: 0.05
                    width: 0.25
              multiple_logos:
                summary: Dealer logo top-left and a brand badge bottom-right
                value:
                  image_url: https://customer-cdn.example.com/listings/42/hero.jpg
                  background_id: white-panels
                  logo:
                    - id: logo_1792240000000.png
                      position: top-left
                    - id: logo_1792240000001.png
                      position: bottom-right
                      width: 0.12
      responses:
        "200":
          description: Generation succeeded.
          headers:
            X-Request-Id:
              schema: { type: string }
              description: Unique request identifier; include this when contacting support.
            X-RateLimit-Limit:
              schema: { type: integer }
              description: Maximum tokens in the per-key bucket.
            X-RateLimit-Remaining:
              schema: { type: integer }
              description: Tokens remaining after this request.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Generation"
        "400":
          $ref: "#/components/responses/InvalidRequest"
        "401":
          $ref: "#/components/responses/InvalidApiKey"
        "402":
          $ref: "#/components/responses/InsufficientCredits"
        "405":
          $ref: "#/components/responses/MethodNotAllowed"
        "422":
          $ref: "#/components/responses/InvalidImage"
        "429":
          $ref: "#/components/responses/RateLimited"
        "500":
          $ref: "#/components/responses/InternalError"
        "502":
          $ref: "#/components/responses/UpstreamUnavailable"

  /v1/logos:
    get:
      tags: [v1]
      summary: List your logos
      description: |
        Lists the workspace's logos, the same ones shown in the app's logo
        picker. Pass an `id` as `logo.id` to `POST /v1/generations`. With
        `?type=plate`, lists the plate logos instead.
      operationId: listLogos
      parameters:
        - $ref: "#/components/parameters/LogoType"
      responses:
        "200":
          description: The workspace's logos, newest first.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/LogoList"
        "401":
          $ref: "#/components/responses/InvalidApiKey"
        "429":
          $ref: "#/components/responses/RateLimited"
        "500":
          $ref: "#/components/responses/InternalError"
    post:
      tags: [v1]
      summary: Upload a logo
      description: |
        Stores a logo for the workspace (PNG, WebP or JPEG, up to 5 MB; use a
        PNG or WebP with a transparent background for the best result). A
        workspace holds up to seven logos; to use more, pass them inline to
        `POST /v1/generations` instead.

        With `?type=plate`, stores a plate logo: the design the generator
        puts on the license plate, filling the whole plate face. Upload it
        with its own background colour, or set `background` to fill a
        transparent one (white by default). Up to seven plate logos.
      operationId: createLogo
      parameters:
        - $ref: "#/components/parameters/LogoType"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/LogoUpload"
            example:
              image_url: https://customer-cdn.example.com/brand/logo.png
      responses:
        "201":
          description: Logo stored.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Logo"
        "400":
          $ref: "#/components/responses/InvalidRequest"
        "401":
          $ref: "#/components/responses/InvalidApiKey"
        "409":
          description: The workspace already has seven logos of this type (`logo_limit_reached`).
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "422":
          $ref: "#/components/responses/InvalidImage"
        "429":
          $ref: "#/components/responses/RateLimited"
        "500":
          $ref: "#/components/responses/InternalError"

  /v1/logos/{id}:
    delete:
      tags: [v1]
      summary: Delete a logo
      operationId: deleteLogo
      parameters:
        - $ref: "#/components/parameters/LogoType"
        - name: id
          in: path
          required: true
          schema: { type: string }
          example: logo_1792240000000.png
      responses:
        "200":
          description: Logo deleted.
          content:
            application/json:
              schema:
                type: object
                required: [id, object, type, deleted]
                properties:
                  id: { type: string }
                  object: { type: string, enum: [logo] }
                  type: { type: string, enum: [logo, plate] }
                  deleted: { type: boolean, enum: [true] }
        "401":
          $ref: "#/components/responses/InvalidApiKey"
        "404":
          description: No logo with that id in the workspace (`not_found`).
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "429":
          $ref: "#/components/responses/RateLimited"
        "500":
          $ref: "#/components/responses/InternalError"

  /v1/backgrounds:
    get:
      tags: [v1]
      summary: List available backgrounds
      description: |
        Lists the backgrounds you can pass as `background_id` to
        `POST /v1/generations`: the built-in catalogue followed by your
        workspace's custom backgrounds (created here or in the app). The set
        may change over time and is workspace-specific, so fetch it instead
        of hard-coding ids.
      operationId: listBackgrounds
      responses:
        "200":
          description: The list of available backgrounds.
          headers:
            X-Request-Id:
              schema: { type: string }
            X-RateLimit-Limit:
              schema: { type: integer }
            X-RateLimit-Remaining:
              schema: { type: integer }
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/BackgroundList"
        "401":
          $ref: "#/components/responses/InvalidApiKey"
        "405":
          $ref: "#/components/responses/MethodNotAllowed"
        "429":
          $ref: "#/components/responses/RateLimited"
        "500":
          $ref: "#/components/responses/InternalError"
        "502":
          $ref: "#/components/responses/UpstreamUnavailable"

    post:
      tags: [v1]
      summary: Create a custom background
      description: |
        Creates a background of your own, such as your showroom or a branded
        studio, from a text description, reference photos, or both. Renders a
        preview (a demo car on the new scene, exactly as generations will
        look) and returns it as `example_url`. Costs one credit; a rejected or
        failed request is not charged. The background is usable in
        `POST /v1/generations` straight away. Look at the preview and refine
        it with `POST /v1/backgrounds/{id}` until it is right.
      operationId: createBackground
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/BackgroundCreate"
            example:
              description: A bright showroom with light oak flooring and floor-to-ceiling windows
      responses:
        "201":
          description: Background created.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Background"
        "400":
          $ref: "#/components/responses/InvalidRequest"
        "401":
          $ref: "#/components/responses/InvalidApiKey"
        "402":
          description: The workspace has no credits left (`insufficient_credits`).
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "422":
          description: |
            The description can't be turned into a background
            (`background_rejected`; the message says why), a reference image
            is invalid (`invalid_image`), or the preview could not be rendered
            (`generation_failed`). Nothing is charged.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "429":
          $ref: "#/components/responses/RateLimited"
        "500":
          $ref: "#/components/responses/InternalError"
        "503":
          description: The preview could not be rendered (`generation_failed`). Nothing is charged; retry.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
  /v1/backgrounds/{id}:
    parameters:
      - name: id
        in: path
        required: true
        schema: { type: string, format: uuid }
        description: The id of one of your custom backgrounds.
    post:
      tags: [v1]
      summary: Refine a custom background
      description: |
        Changes a custom background and renders a new preview. `description`
        is the change to make ("make the floor darker and the lighting
        warmer"); everything else is kept. Costs one credit.
      operationId: refineBackground
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/BackgroundRefine"
            example:
              description: Make the floor darker and the lighting warmer
      responses:
        "200":
          description: Background updated.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Background"
        "400":
          $ref: "#/components/responses/InvalidRequest"
        "404":
          description: No custom background with that id in the workspace (`not_found`).
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "401":
          $ref: "#/components/responses/InvalidApiKey"
        "402":
          description: The workspace has no credits left (`insufficient_credits`).
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "422":
          description: |
            The description can't be turned into a background
            (`background_rejected`; the message says why), a reference image
            is invalid (`invalid_image`), or the preview could not be rendered
            (`generation_failed`). Nothing is charged.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "429":
          $ref: "#/components/responses/RateLimited"
        "500":
          $ref: "#/components/responses/InternalError"
        "503":
          description: The preview could not be rendered (`generation_failed`). Nothing is charged; retry.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
    delete:
      tags: [v1]
      summary: Delete a custom background
      description: Photos already generated with it are not affected.
      operationId: deleteBackground
      responses:
        "200":
          description: Background deleted.
          content:
            application/json:
              schema:
                type: object
                required: [id, object, deleted]
                properties:
                  id: { type: string }
                  object: { type: string, enum: [background] }
                  deleted: { type: boolean, enum: [true] }
        "401":
          $ref: "#/components/responses/InvalidApiKey"
        "404":
          description: No custom background with that id in the workspace (`not_found`).
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "429":
          $ref: "#/components/responses/RateLimited"
        "500":
          $ref: "#/components/responses/InternalError"
  /v1/credits:
    get:
      tags: [v1]
      summary: Get your credit balance
      description: Returns the workspace's current credit balance.
      operationId: getCredits
      responses:
        "200":
          description: The workspace's current credit balance.
          headers:
            X-Request-Id:
              schema: { type: string }
            X-RateLimit-Limit:
              schema: { type: integer }
            X-RateLimit-Remaining:
              schema: { type: integer }
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Credits"
        "401":
          $ref: "#/components/responses/InvalidApiKey"
        "405":
          $ref: "#/components/responses/MethodNotAllowed"
        "429":
          $ref: "#/components/responses/RateLimited"
        "500":
          $ref: "#/components/responses/InternalError"
        "502":
          $ref: "#/components/responses/UpstreamUnavailable"

  /v1/plates:
    post:
      tags: [v1]
      summary: Hide license plates
      description: |
        Finds every license plate in a car photo, including small plates on
        cars in the background, and hides it with a blur or a solid block.
        Everything else in the photo is unchanged: same size, same format
        (unless you ask for another), and location (GPS) metadata is removed
        by default. The image is returned inline and is not stored.

        Included with any active subscription, at no credit cost, up to 2,000
        photos per workspace per calendar month (UTC). Every request that
        passes validation counts towards the limit. Typically 2-4s.
      operationId: hidePlates
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/PlateRequest"
            examples:
              blur:
                summary: Blur plates, keep the input format
                value:
                  image_url: https://customer-cdn.example.com/listings/42/rear.jpg
              block:
                summary: White block, WebP output
                value:
                  image_base64: "/9j/4AAQSkZJRgABAQEASABIAAD..."
                  style: block
                  block_color: "#FFFFFF"
                  output_format: webp
      responses:
        "200":
          description: Plates hidden.
          headers:
            X-Request-Id:
              schema: { type: string }
            X-RateLimit-Limit:
              schema: { type: integer }
            X-RateLimit-Remaining:
              schema: { type: integer }
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PlateBlur"
        "400":
          $ref: "#/components/responses/InvalidRequest"
        "401":
          $ref: "#/components/responses/InvalidApiKey"
        "403":
          $ref: "#/components/responses/SubscriptionRequired"
        "405":
          $ref: "#/components/responses/MethodNotAllowed"
        "422":
          $ref: "#/components/responses/InvalidImage"
        "429":
          description: |
            Per-key rate limit exceeded (`rate_limited`, with `Retry-After`), or
            the workspace's monthly plate limit is reached
            (`plate_quota_exceeded`; contact us for a higher limit).
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "500":
          $ref: "#/components/responses/InternalError"
        "503":
          description: Plate detection failed (`detection_failed`). Retry the request.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }

components:
  securitySchemes:
    apiKey:
      type: http
      scheme: bearer
      bearerFormat: cbg_*
      description: |
        Pass your API key as `Authorization: Bearer cbg_<secret>`. Create and
        manage keys at https://app.carbackground.ai/settings/api-keys.

  parameters:
    LogoType:
      name: type
      in: query
      required: false
      schema:
        type: string
        enum: [logo, plate]
        default: logo
      description: |
        Which logo library: `logo` (drawn on finished photos) or `plate`
        (put on the car's license plate by the generator).

  schemas:
    GenerationRequest:
      type: object
      required: [background_id]
      properties:
        image_url:
          type: string
          format: uri
          description: |
            HTTPS URL of the source car photo. Maximum 50 MB. Supported
            content-types: image/jpeg, image/png, image/webp. Either
            `image_url` or `image_base64` must be set, not both.
        image_base64:
          type: string
          description: |
            Base64-encoded image bytes. Accepts both raw base64 and a
            `data:image/...;base64,...` data URL. Same size and type
            constraints as `image_url`.
        background_id:
          $ref: "#/components/schemas/BackgroundId"
        hide_license_plate:
          type: boolean
          default: false
          description: |
            Hide a legible license plate, in the style set by
            `license_plate_style`. Photos without a visible plate are left
            unchanged. Applies to exterior photos only.
        license_plate_style:
          type: string
          enum: [plain, blur, logo]
          default: plain
          description: |
            How `hide_license_plate` hides the plate. `plain` replaces it with
            a plain plate of the same colour (no characters, symbols or country
            band); `blur` blurs the whole plate so nothing on it can be read,
            keeping its shape and position; `logo` replaces it with a plate
            showing `license_plate_logo`, following the plate's angle. Ignored
            unless `hide_license_plate` is true. With `logo`, a car far from
            the camera may come out a little larger.
        license_plate_logo:
          type: object
          description: |
            Required with `license_plate_style: logo`. Set exactly one of
            `id` (a plate logo from `GET /v1/logos?type=plate`),
            `image_url` or `image_base64`. The logo fills the whole plate
            face; a transparent logo sits on its plate colour.
          properties:
            id:
              type: string
              example: plate_1792240000000.bg-ffffff.png
            image_url:
              type: string
              format: uri
            image_base64:
              type: string
            background:
              type: string
              pattern: "^#[0-9a-fA-F]{6}$"
              example: "#0F2A4A"
              description: |
                Inline logos only: the plate colour behind a transparent logo.
                Default white. A stored plate logo uses its own.
        center_car:
          type: boolean
          default: false
          description: |
            **Experimental.** Frame the car like a dealership listing photo:
            centred, enlarged and levelled if the photo was taken crooked,
            keeping its viewing angle. A car cut off at an edge of the photo
            stays cut off at that edge. `false` keeps the car's original size
            and position. Applies to exterior photos only. Results can be
            unexpected: details of the car may be invented or not fully kept.
        clean_car:
          type: boolean
          default: false
          description: |
            **Experimental.** Show the car freshly washed: removes dirt a car
            wash would remove (dust, mud, water spots, insects) and keeps
            permanent marks such as scratches, dents and rust. `false` keeps
            the car as photographed. Applies to exterior photos only. Results
            can be unexpected: details of the car may be invented or not fully
            kept.
        aspect_ratio:
          type: string
          enum:
            [
              "1:1",
              "16:9",
              "9:16",
              "4:3",
              "3:4",
              "3:2",
              "2:3",
              "4:5",
              "5:4",
              "21:9",
            ]
          description: |
            Output aspect ratio; omit to keep the input photo's. The scene is
            extended or the view tightened to fit, never by adding parts of
            the car that are not in the photo. Interior and detail photos keep
            their original ratio.
        logo:
          description: |
            One logo, or a list of up to seven drawn in order (later ones on
            top).
          oneOf:
            - $ref: "#/components/schemas/LogoPlacement"
            - type: array
              minItems: 1
              maxItems: 7
              items:
                $ref: "#/components/schemas/LogoPlacement"

    LogoPlacement:
      type: object
      description: |
        Draws a logo onto the result. Set exactly one of `id`, `image_url` or
        `image_base64`. Place it with a `position` preset (default
        `bottom-right`) or with `x` and `y`. The result keeps a copy without
        the logo in your workspace library. A logo that can't be read returns
        `422 invalid_logo` and no credit is charged.
      properties:
        id:
          type: string
          description: A logo from `GET /v1/logos`.
        image_url:
          type: string
          format: uri
          description: A PNG, WebP or JPEG logo (up to 5 MB), not stored.
        image_base64:
          type: string
          description: The same, base64-encoded (raw or a data URL).
        position:
          type: string
          enum: [top-left, top-right, bottom-left, bottom-right, top-center]
          default: bottom-right
          description: |
            Corner presets sit 4% (of the shorter side) in from the edges;
            `top-center` suits a wide logo shown like wall signage.
        x:
          type: number
          minimum: 0
          maximum: 1
          description: |
            Instead of `position`: the logo's left edge as a fraction of the
            image width. Set together with `y`. Kept inside the image.
        y:
          type: number
          minimum: 0
          maximum: 1
          description: The logo's top edge as a fraction of the image height.
        width:
          type: number
          minimum: 0.05
          maximum: 1
          description: |
            Logo width as a fraction of the image width. Default 0.2 (0.3 for
            `top-center`). The height follows the logo's own proportions.

    LogoUpload:
      type: object
      description: Set exactly one of `image_url` or `image_base64`.
      properties:
        image_url:
          type: string
          format: uri
        image_base64:
          type: string
        background:
          type: string
          pattern: "^#[0-9a-fA-F]{6}$"
          example: "#0F2A4A"
          description: |
            Plate logos only (`?type=plate`): the colour that fills the logo's
            transparent pixels, as the plate's background. Default white.

    Logo:
      type: object
      required: [id, object, type, image_url, created_at]
      properties:
        id:
          type: string
          example: logo_1792240000000.png
        object:
          type: string
          enum: [logo]
        type:
          type: string
          enum: [logo, plate]
          description: "`logo` for logos drawn on photos, `plate` for plate logos."
        background:
          type: string
          example: "#0f2a4a"
          description: |
            Plate logos only: the plate colour shown behind a transparent
            logo, as set on upload.
        image_url:
          type: string
          format: uri
          description: Signed URL of the logo, valid for 7 days.
        created_at:
          type: ["string", "null"]
          format: date-time

    LogoList:
      type: object
      required: [object, data]
      properties:
        object:
          type: string
          enum: [list]
        data:
          type: array
          items:
            $ref: "#/components/schemas/Logo"

    BackgroundId:
      type: string
      description: |
        Identifier of the background scene to apply: either a built-in scene
        slug (e.g. `white-panels`) or the UUID of one of your workspace's
        custom backgrounds. Call `GET /v1/backgrounds` for the current list of
        ids — the set changes over time and is workspace-specific, so do not
        hard-code it.
      examples:
        - white-panels
        - 3fa85f64-5717-4562-b3fc-2c963f66afa6

    Generation:
      type: object
      required:
        - id
        - object
        - status
        - image_url
        - background_id
        - credits_charged
        - created_at
      properties:
        id:
          type: string
          example: gen_01HXYZABCDEF...
          description: Unique generation identifier.
        object:
          type: string
          enum: [generation]
        status:
          type: string
          enum: [succeeded]
        image_url:
          type: string
          format: uri
          description: |
            Signed URL to the generated image, with the logo drawn on when
            `logo` was set. Valid for 7 days.
        background_id:
          $ref: "#/components/schemas/BackgroundId"
        credits_charged:
          type: integer
          example: 1
        created_at:
          type: string
          format: date-time

    PlateRequest:
      type: object
      properties:
        image_url:
          type: string
          format: uri
          description: |
            HTTPS URL of the car photo. Maximum 20 MB. Supported content-types:
            image/jpeg, image/png, image/webp. Either `image_url` or
            `image_base64` must be set, not both.
        image_base64:
          type: string
          description: |
            Base64-encoded image bytes, raw or as a `data:image/...;base64,...`
            data URL. Same size and type constraints as `image_url`.
        style:
          type: string
          enum: [blur, block]
          default: blur
          description: Blur the plate, or cover it with a solid block.
        block_color:
          type: string
          default: "#000000"
          description: Hex colour of the block when `style` is `block`.
          example: "#FFFFFF"
        output_format:
          type: string
          enum: [auto, jpeg, png, webp]
          default: auto
          description: "`auto` returns the same format as the input."
        keep_metadata:
          type: boolean
          default: false
          description: |
            Keep the photo's EXIF metadata. By default it is removed, including
            the GPS location where the photo was taken.

    PlateBlur:
      type: object
      required:
        [id, object, status, plates, image_base64, mime_type, created_at]
      properties:
        id:
          type: string
          example: plt_9b75644c-ea48-45db-a966-6956cb214e7a
        object:
          type: string
          enum: [plate_blur]
        status:
          type: string
          enum: [succeeded]
        plates:
          type: array
          description: |
            The areas that were hidden (each plate plus a small margin), as
            `[ymin, xmin, ymax, xmax]` normalised to 0-1000 of the image height
            and width. Empty when no plate was found (the image is still
            returned, with metadata removed unless `keep_metadata` is set).
          items:
            type: array
            items: { type: integer }
            minItems: 4
            maxItems: 4
          example: [[621, 344, 693, 680]]
        image_base64:
          type: string
          description: The result image, base64-encoded.
        mime_type:
          type: string
          enum: [image/jpeg, image/png, image/webp]
        created_at:
          type: string
          format: date-time

    Background:
      type: object
      required: [id, name, preview_url, example_url, custom]
      properties:
        id:
          $ref: "#/components/schemas/BackgroundId"
        name:
          type: string
          description: Human-readable display name.
          example: White Panels
        preview_url:
          type: ["string", "null"]
          format: uri
          description: |
            Clean, car-free preview of the background scene. `null` for custom
            backgrounds.
        example_url:
          type: ["string", "null"]
          format: uri
          description: |
            Example showing a sample car composited on the scene. For custom
            backgrounds a signed URL valid for 7 days, or `null` if it has no
            preview yet.
        custom:
          type: boolean
          description: |
            `true` for a custom background owned by your workspace, `false`
            for a built-in scene.
        feedback:
          type: string
          description: |
            Only when creating or refining: the part of the request that
            could not be honoured, if any.

    BackgroundCreate:
      type: object
      description: Set `description`, `reference_image_urls`, or both.
      properties:
        description:
          type: string
          maxLength: 2000
          description: The scene, e.g. walls, floor, lighting and setting.
        reference_image_urls:
          type: array
          maxItems: 3
          items: { type: string, format: uri }
          description: Photos of the place or style to recreate (JPEG, PNG or WebP, up to 20 MB each).
        base_background_id:
          type: string
          description: |
            A built-in background to start from; `description` then says what
            to change.
          example: white-panels
        name:
          type: string
          maxLength: 80
          description: Display name. One is suggested if omitted.

    BackgroundRefine:
      type: object
      description: Set `description`, `reference_image_urls`, or both.
      properties:
        description:
          type: string
          maxLength: 2000
          description: The change to make to the background.
        reference_image_urls:
          type: array
          maxItems: 3
          items: { type: string, format: uri }

    BackgroundList:
      type: object
      required: [object, data]
      properties:
        object:
          type: string
          enum: [list]
        data:
          type: array
          items:
            $ref: "#/components/schemas/Background"

    Credits:
      type: object
      required: [object, balance]
      properties:
        object:
          type: string
          enum: [credits]
        balance:
          type: integer
          description: Credits currently available to the workspace.
          example: 142

    Error:
      type: object
      required: [error]
      properties:
        error:
          type: object
          required: [code, message, request_id]
          properties:
            code:
              type: string
              enum:
                - invalid_api_key
                - insufficient_credits
                - invalid_image
                - invalid_request
                - rate_limited
                - method_not_allowed
                - generation_failed
                - subscription_required
                - plate_quota_exceeded
                - detection_failed
                - invalid_logo
                - logo_limit_reached
                - internal_error
                - upstream_unavailable
                - not_found
            message:
              type: string
              description: Human-readable summary, may change between releases.
            request_id:
              type: string
              description: Echoes `X-Request-Id` so it appears in customer logs.

  responses:
    InvalidRequest:
      description: Request body is malformed (e.g., not valid JSON).
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
    InvalidApiKey:
      description: API key is missing, malformed, unknown, or revoked.
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
    InsufficientCredits:
      description: Workspace has no credits remaining.
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
    SubscriptionRequired:
      description: The endpoint requires an active subscription on the workspace.
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
    MethodNotAllowed:
      description: HTTP method not supported on this endpoint.
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
    InvalidImage:
      description: Image input was missing, oversized, wrong type, or unfetchable.
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
    RateLimited:
      description: Per-key rate limit exceeded.
      headers:
        Retry-After:
          schema: { type: integer }
          description: Seconds until at least one token refills.
        X-RateLimit-Limit:
          schema: { type: integer }
        X-RateLimit-Remaining:
          schema: { type: integer }
        X-RateLimit-Reset:
          schema: { type: integer }
          description: Unix epoch seconds when the bucket has capacity again.
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
    InternalError:
      description: Unexpected server error. Include `request_id` when contacting support.
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
    UpstreamUnavailable:
      description: |
        Temporary service error (`upstream_unavailable`, status 502 or 503).
        Retry with exponential backoff. A 503 means nothing was processed or
        charged and includes `Retry-After`.
      headers:
        Retry-After:
          schema: { type: integer }
          description: Seconds to wait before retrying (503 only).
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
