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

# OpenAI 채팅 형식

> OpenAI-compatible Chat Completions for standard multi-turn chat, structured output, and tool calling. Model names use the `provider/model-name` format, for example `openai/gpt-4o`. Image-capable models can also return generated images through this endpoint.

이 페이지는 [채팅 완성 생성](/ko/api-reference/chat/create-chat-completion)과 동일한 `chat/completions` 작업을 사용하며, 위의 플레이그라운드에는 일반적인 채팅 스키마가 미리 입력되어 있습니다. 아래 내용은 OpenAI 호환 클라이언트에서 이 엔드포인트를 사용하여 Gemini 기반 이미지 생성을 요청하는 방법을 설명합니다.

<Note>
  `model`에 이미지 생성 모델(예: `gemini-2.0-flash-preview-image-generation`)을 포함하고, 필요에 따라 `stream`을 설정하며, `messages`를 통해 프롬프트를 제공하세요. 선택적으로 `messages`와 함께 추가적인 Gemini 스타일 멀티모달 컨텍스트를 위해 `contents`를 포함할 수 있습니다.
</Note>

### 제공자별 참고 사항

| 필드                   | 유형     | 필수  | 설명                                                                     |
| -------------------- | ------ | --- | ---------------------------------------------------------------------- |
| `model`              | string | 예   | 이미지 생성 모델 식별자입니다 (예: `gemini-2.0-flash-preview-image-generation`).     |
| `messages[].content` | string | 예   | 원하는 이미지를 설명하는 프롬프트 텍스트입니다.                                             |
| `contents`           | array  | 아니요 | 추가적인 멀티모달 컨텍스트를 위한 선택적 Gemini 스타일 콘텐츠 배열로, 표준 OpenAI 채팅 스키마의 일부가 아닙니다. |

<Tip>
  `contents` 필드는 표준 채팅 완성 스키마 위에 추가된 DGrid 확장 기능입니다 — 대상 모델이 지원하는 경우, OpenAI 스타일의 `messages` 배열과 함께 Gemini 네이티브 `parts`(예: `inlineData`)를 전달할 수 있게 해줍니다.
</Tip>

### 예시: 이미지 요청

```json theme={null}
{
  "model": "gemini-2.0-flash-preview-image-generation",
  "stream": false,
  "messages": [
    {
      "role": "user",
      "content": "Generate an image of a futuristic city skyline at sunset."
    }
  ]
}
```

### 응답 필드

응답은 표준 채팅 완성 형식을 따릅니다. 생성된 이미지는 어시스턴트 메시지 콘텐츠에 직접 포함됩니다.

<ResponseField name="choices" type="array">
  반환된 선택 항목입니다.

  <Expandable title="choice properties">
    <ResponseField name="index" type="integer">
      선택 항목의 인덱스입니다.
    </ResponseField>

    <ResponseField name="message" type="object">
      어시스턴트 메시지 객체입니다.

      <Expandable title="message properties">
        <ResponseField name="role" type="string">
          메시지 역할로, 일반적으로 `assistant`입니다.
        </ResponseField>

        <ResponseField name="content" type="string">
          메시지 콘텐츠입니다. 이미지 출력 모델의 경우, 생성된 이미지를 base64 데이터 URI로 임베딩한 마크다운 이미지 참조입니다 (예: `![generated image](data:image/png;base64,...)`).
        </ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="finish_reason" type="string">
      종료 이유입니다 (예: `stop`).
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="usage" type="object">
  토큰 사용량 요약입니다.
</ResponseField>

### 응답 예시

```json 200 theme={null}
{
  "id": "chatcmpl-abc123",
  "model": "gemini-2.0-flash-preview-image-generation",
  "object": "chat.completion",
  "created": 1719859200,
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "![generated image](data:image/png;base64,<base64-encoded-image-bytes>)"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 12,
    "completion_tokens": 0,
    "total_tokens": 12
  }
}
```


## OpenAPI

````yaml api-reference/openapi.json POST /v1/chat/completions
openapi: 3.1.0
info:
  title: DGrid AI Gateway API
  description: >-
    A single, unified API to access 200+ leading AI models. OpenAI-, Claude-,
    and Gemini-compatible endpoints for chat, completions, embeddings, images,
    audio, and moderations.
  version: 1.0.0
  contact:
    name: DGrid AI
    url: https://dgrid.ai
servers:
  - url: https://api.dgrid.ai
    description: DGrid AI Gateway
security:
  - bearerAuth: []
paths:
  /v1/chat/completions:
    post:
      tags:
        - Chat
      summary: Create chat completion
      description: >-
        OpenAI-compatible Chat Completions for standard multi-turn chat,
        structured output, and tool calling. Model names use the
        `provider/model-name` format, for example `openai/gpt-4o`. Image-capable
        models can also return generated images through this endpoint.
      operationId: createChatCompletion
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - model
                - messages
              properties:
                model:
                  type: string
                  description: Target model ID in `provider/model-name` format.
                  example: openai/gpt-4o
                messages:
                  type: array
                  description: Conversation message list.
                  items:
                    type: object
                    required:
                      - role
                      - content
                    properties:
                      role:
                        type: string
                        enum:
                          - system
                          - user
                          - assistant
                          - tool
                        description: Message author role.
                      content:
                        type: string
                        description: Message content.
                      name:
                        type: string
                        description: Optional participant name.
                      tool_calls:
                        type: array
                        description: Tool invocation payloads.
                        items:
                          type: object
                      tool_call_id:
                        type: string
                        description: Tool call identifier.
                temperature:
                  type: number
                  default: 1
                  description: Sampling temperature.
                top_p:
                  type: number
                  default: 1
                  description: Nucleus sampling value.
                'n':
                  type: integer
                  default: 1
                  description: Number of choices to generate.
                stream:
                  type: boolean
                  default: false
                  description: Enable SSE streaming.
                max_tokens:
                  type: integer
                  description: Maximum token count.
                max_completion_tokens:
                  type: integer
                  description: Max completion-only tokens.
                presence_penalty:
                  type: number
                  default: 0
                  description: Presence penalty.
                frequency_penalty:
                  type: number
                  default: 0
                  description: Frequency penalty.
                logit_bias:
                  type: object
                  description: Token bias configuration.
                stop:
                  description: Stop sequence string or array.
                  oneOf:
                    - type: string
                    - type: array
                      items:
                        type: string
                tools:
                  type: array
                  description: Tool definitions.
                  items:
                    type: object
                tool_choice:
                  description: Tool selection behavior. Defaults to `auto`.
                  oneOf:
                    - type: string
                    - type: object
                response_format:
                  type: object
                  description: Response schema or JSON mode config.
                seed:
                  type: integer
                  description: Deterministic seed.
                user:
                  type: string
                  description: End-user identifier.
            example:
              model: openai/gpt-4o
              messages:
                - role: user
                  content: What is the meaning of life?
      responses:
        '200':
          description: Chat completion result.
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    description: Completion identifier.
                  object:
                    type: string
                    description: Always `chat.completion`.
                  created:
                    type: integer
                    description: Creation timestamp.
                  model:
                    type: string
                    description: Model that served the request.
                  choices:
                    type: array
                    description: Returned choices.
                    items:
                      type: object
                      properties:
                        index:
                          type: integer
                          description: Choice index.
                        message:
                          type: object
                          description: Assistant message object.
                          properties:
                            role:
                              type: string
                              description: Response role.
                            content:
                              type: string
                              description: Response text.
                            reasoning_content:
                              type: string
                              description: Reasoning trace for reasoning models.
                            tool_calls:
                              type: array
                              description: Tool call payloads.
                              items:
                                type: object
                        finish_reason:
                          type: string
                          description: '`stop`, `length`, `content_filter`, or `tool_calls`.'
                  usage:
                    $ref: '#/components/schemas/Usage'
                  system_fingerprint:
                    type: string
        '400':
          $ref: '#/components/responses/BadRequest'
        '429':
          $ref: '#/components/responses/RateLimited'
components:
  schemas:
    Usage:
      type: object
      description: Token usage breakdown.
      properties:
        prompt_tokens:
          type: integer
        completion_tokens:
          type: integer
        total_tokens:
          type: integer
        prompt_tokens_details:
          type: object
          properties:
            cached_tokens:
              type: integer
            text_tokens:
              type: integer
            audio_tokens:
              type: integer
            image_tokens:
              type: integer
        completion_tokens_details:
          type: object
          properties:
            text_tokens:
              type: integer
            audio_tokens:
              type: integer
            reasoning_tokens:
              type: integer
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
            type:
              type: string
            param:
              type: string
            code:
              type: string
  responses:
    BadRequest:
      description: Invalid request.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    RateLimited:
      description: Rate limit exceeded.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        Your DGrid API key. All endpoints use `Authorization: Bearer
        <DGRID_API_KEY>`.

````