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

# Créer une complétion de chat

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



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

````