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

# openai compat generate

> generate a image

```xml theme={null}
<dependency>
    <groupId>com.openai</groupId>
    <artifactId>openai-java</artifactId>
    <version>x.x.x</version>
</dependency>
```

## Normal Request Example

<Tabs>
  <Tab title="Java">
    ```java theme={null}
    @Test
    void imageGenerateTest() {
        OpenAIClient client = OpenAIOkHttpClient.builder()
                .apiKey(apiKey)
                .baseUrl("https://ai.pmock.com/api/ai/openai/v1")
                .build();

        ImageGenerateParams params = ImageGenerateParams.builder()
                .prompt("a cute cat")
                .responseFormat(ImageGenerateParams.ResponseFormat.B64_JSON)
                .build();
        ImagesResponse imagesResponse = client.images().generate(params);
        System.out.println(imagesResponse.data());
    }
    ```
  </Tab>
</Tabs>


## OpenAPI

````yaml post /ai/openai/v1/images/generations
openapi: 3.1.0
info:
  title: OpenAPI definition
  version: v0
servers:
  - url: https://ai.pmock.com/api
    description: Generated server url
security: []
tags:
  - name: 开放-百度视频生成
    description: 开放-百度视频生成
  - name: 开放-Grok开放接口
    description: 开放-Grok开放接口
  - name: 开放-Gemini开放接口
    description: 开放-Gemini开放接口
  - name: 开放-AI对话开放接口
    description: 开放-AI对话开放接口
  - name: 开放-Sora2开放接口
    description: 开放-Sora2开放接口
  - name: 开放-模型列表接口
    description: 开放-模型列表接口
  - name: 开放-OpenAi开放接口
    description: 开放-OpenAi开放接口
  - name: 开放-业务相关接口
    description: 开放-业务相关接口
  - name: 开放-任务开放接口
    description: 开放-任务开放接口
paths:
  /ai/openai/v1/images/generations:
    post:
      tags:
        - 开放-OpenAi开放接口
      summary: openai compat generate
      description: generate a image
      operationId: openAiCompatImageGenerate
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/OpenAiCompatImageGenerateDTO'
        required: true
      responses:
        '200':
          description: OK
          content:
            '*/*':
              schema:
                type: object
components:
  schemas:
    OpenAiCompatImageGenerateDTO:
      type: object
      properties:
        prompt:
          type: string
          description: prompt
          minLength: 1
        background:
          type: string
          description: background transparency
          enum:
            - transparent
            - opaque
            - auto
          title: 'transparent : transparent; opaque : opaque; auto : auto'
        model:
          type: string
          default: gpt-image-2
          description: model
          enum:
            - gpt-image-2
        moderation:
          type: string
          description: Audit intensity
          enum:
            - auto
            - low
          title: 'auto : auto; low : low'
        'n':
          type: integer
          format: int32
          description: Generation quantity (currently only supports 1)
        outputCompression:
          type: integer
          format: int32
          description: JPEG/WebP compression level 0-100
        outputFormat:
          type: string
          description: Output file format
          enum:
            - png
            - jpeg
            - webp
          title: 'png : png; jpeg : jpeg; webp : webp'
        partialImages:
          type: integer
          format: int32
          description: partial images
        quality:
          type: string
          default: auto
          description: quality grade
          enum:
            - auto
            - low
            - medium
            - high
            - standard
          title: >-
            auto : auto; low : low; medium : medium; high : high; standard :
            standard
        responseFormat:
          type: string
          description: >-
            Response format (compatible with DALL · E; The gpt image series
            always returns b64_json)
          enum:
            - url
            - b64_json
          title: 'url : url; b64_json : b64_json'
        size:
          type: string
          default: 1024x1024
          description: >-
            image size, ① Single side ≤ 3840 px; ② Both width and height are
            multiples of 16;③ Long side : short side ≤ 3:1; ④ Total pixels ∈
            [655,360, 8,294,400]. Requests that do not meet the constraints or
            are not supported by the channel for custom sizes will be rejected
          enum:
            - auto
            - 1024x1024
            - 1024x1536
            - 1536x1024
            - 2048x2048
            - 2048x1152
            - 3840x2160
            - 2160x3840
        inputFidelity:
          type: string
          description: >-
            Input image fidelity (newly added in gpt-image-2, only effective for
            editing scenes); Generate can be ignored)
          enum:
            - high
            - low
          title: 'high : high; low : low'
        user:
          type: string
          description: user
      required:
        - model
        - prompt
        - quality

````