> ## 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 Chat Format

> 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.

This page uses the same `chat/completions` operation as [Create chat completion](/api-reference/chat/create-chat-completion), with the playground above pre-filled for the generic chat schema. The notes below describe how to use this endpoint to request Gemini-backed image generation from an OpenAI-compatible client.

<Note>
  Include an image-generation model in `model` (such as `gemini-2.0-flash-preview-image-generation`), set `stream` as needed, and supply your prompt through `messages`. Optionally include `contents` for additional Gemini-style multimodal context alongside `messages`.
</Note>

### Provider-specific notes

| Field                | Type   | Required | Description                                                                                                         |
| -------------------- | ------ | -------- | ------------------------------------------------------------------------------------------------------------------- |
| `model`              | string | Yes      | Image-generation model identifier, e.g. `gemini-2.0-flash-preview-image-generation`.                                |
| `messages[].content` | string | Yes      | Prompt text describing the desired image.                                                                           |
| `contents`           | array  | No       | Optional Gemini-style content array for additional multimodal context, not part of the standard OpenAI chat schema. |

<Tip>
  The `contents` field is a DGrid extension layered on top of the standard chat completions schema — it lets you pass Gemini-native `parts` (such as `inlineData`) alongside the OpenAI-style `messages` array when the target model supports it.
</Tip>

### Example: requesting an image

```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."
    }
  ]
}
```

### Response fields

The response follows the standard chat completions shape. The generated image is embedded directly in the assistant message content:

<ResponseField name="choices" type="array">
  Returned choice entries.

  <Expandable title="choice properties">
    <ResponseField name="index" type="integer">
      Choice index.
    </ResponseField>

    <ResponseField name="message" type="object">
      Assistant message object.

      <Expandable title="message properties">
        <ResponseField name="role" type="string">
          Message role, typically `assistant`.
        </ResponseField>

        <ResponseField name="content" type="string">
          Message content. For image-output models, this is a markdown image reference embedding the generated image as a base64 data URI, e.g. `![generated image](data:image/png;base64,...)`.
        </ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="finish_reason" type="string">
      Finish reason, e.g. `stop`.
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="usage" type="object">
  Token usage summary.
</ResponseField>

### Example response

```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>`.

````