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

# Chat Completion

> Creates a synchronous chat completion from an OpenAI-compatible request. Provider failures preserve an upstream 4xx status when applicable and use the provider_error code; upstream 5xx failures return 503.



## OpenAPI

````yaml /hub/openapi/hub.json post /api/v1/hub/chat/completions
openapi: 3.0.1
info:
  title: Fanify Hub API
  description: Generate media and text with Fanify credits. All prices use EUR.
  version: v1
servers:
  - url: https://fanifyai.com
security: []
paths:
  /api/v1/hub/chat/completions:
    post:
      tags:
        - Chat
      summary: Chat Completion
      description: >-
        Creates a synchronous chat completion from an OpenAI-compatible request.
        Provider failures preserve an upstream 4xx status when applicable and
        use the provider_error code; upstream 5xx failures return 503.
      parameters:
        - name: Idempotency-Key
          in: header
          description: Optional idempotency key, from 1 to 255 characters.
          schema:
            type: string
      requestBody:
        description: >-
          OpenAI-compatible chat completion request. Additional top-level fields
          are forwarded. The stream field must be omitted or false; n is not
          supported and must be omitted.
        content:
          application/json:
            schema:
              required:
                - model
                - messages
              type: object
              properties:
                model:
                  type: string
                messages:
                  type: array
                  items:
                    type: object
            example:
              model: deepseek-v4-flash-0731
              messages:
                - role: user
                  content: Hello
        required: true
      responses:
        '200':
          description: OpenAI-compatible chat completion.
          headers:
            X-Fanify-Generation-Id:
              description: Hub generation identifier.
              schema:
                type: string
            X-Fanify-Billed-Cost:
              description: Billed cost in EUR, using invariant decimal notation.
              schema:
                type: string
          content:
            application/json:
              schema:
                type: object
              example:
                id: 0192f3a4-8c1e-7b2a-9f10-2b6d4e0c9a11
                object: chat.completion
                created: 1757239231
                model: deepseek-v4-flash-0731
                choices:
                  - index: 0
                    message:
                      role: assistant
                      content: Hello!
                    finish_reason: stop
                usage:
                  prompt_tokens: 10
                  completion_tokens: 120
                  total_tokens: 130
                  cost: 0.000041
        '400':
          description: OpenAI-compatible error.
          content:
            application/json:
              schema:
                required:
                  - error
                type: object
                properties:
                  error:
                    required:
                      - message
                      - code
                      - type
                      - metadata
                    type: object
                    properties:
                      message:
                        type: string
                      code:
                        enum:
                          - invalid_input
                          - provider_error
                        type: string
                      type:
                        type: string
                      metadata:
                        required:
                          - provider_name
                        type: object
                        properties:
                          provider_name:
                            enum:
                              - FanifyHub
                            type: string
              example:
                error:
                  message: The request input is invalid.
                  code: invalid_input
                  type: invalid_request_error
                  metadata:
                    provider_name: FanifyHub
        '401':
          description: Unauthorized
          content:
            application/problem+json:
              schema:
                required:
                  - type
                  - title
                  - status
                  - code
                type: object
                properties:
                  type:
                    type: string
                    format: uri
                  title:
                    type: string
                  status:
                    type: integer
                    format: int32
                  detail:
                    type: string
                    nullable: true
                  instance:
                    type: string
                  code:
                    enum:
                      - unauthorized
                    type: string
                  errors:
                    type: object
                    additionalProperties:
                      type: array
                      items:
                        type: string
                  unrepresentable:
                    type: array
                    items:
                      type: string
              example:
                type: https://fanifyai.com/docs/hub/errors#unauthorized
                title: Unauthorized
                status: 401
                code: unauthorized
        '402':
          description: OpenAI-compatible error.
          content:
            application/json:
              schema:
                required:
                  - error
                type: object
                properties:
                  error:
                    required:
                      - message
                      - code
                      - type
                      - metadata
                    type: object
                    properties:
                      message:
                        type: string
                      code:
                        enum:
                          - insufficient_credits
                        type: string
                      type:
                        type: string
                      metadata:
                        required:
                          - provider_name
                        type: object
                        properties:
                          provider_name:
                            enum:
                              - FanifyHub
                            type: string
              example:
                error:
                  message: Your available balance does not cover this generation.
                  code: insufficient_credits
                  type: invalid_request_error
                  metadata:
                    provider_name: FanifyHub
        '404':
          description: OpenAI-compatible error.
          content:
            application/json:
              schema:
                required:
                  - error
                type: object
                properties:
                  error:
                    required:
                      - message
                      - code
                      - type
                      - metadata
                    type: object
                    properties:
                      message:
                        type: string
                      code:
                        enum:
                          - model_not_found
                        type: string
                      type:
                        type: string
                      metadata:
                        required:
                          - provider_name
                        type: object
                        properties:
                          provider_name:
                            enum:
                              - FanifyHub
                            type: string
              example:
                error:
                  message: The requested model was not found.
                  code: model_not_found
                  type: invalid_request_error
                  metadata:
                    provider_name: FanifyHub
        '410':
          description: OpenAI-compatible error.
          content:
            application/json:
              schema:
                required:
                  - error
                type: object
                properties:
                  error:
                    required:
                      - message
                      - code
                      - type
                      - metadata
                    type: object
                    properties:
                      message:
                        type: string
                      code:
                        enum:
                          - file_expired
                        type: string
                      type:
                        type: string
                      metadata:
                        required:
                          - provider_name
                        type: object
                        properties:
                          provider_name:
                            enum:
                              - FanifyHub
                            type: string
              example:
                error:
                  message: The requested file has expired or is unavailable.
                  code: file_expired
                  type: invalid_request_error
                  metadata:
                    provider_name: FanifyHub
        '422':
          description: OpenAI-compatible error.
          content:
            application/json:
              schema:
                required:
                  - error
                type: object
                properties:
                  error:
                    required:
                      - message
                      - code
                      - type
                      - metadata
                    type: object
                    properties:
                      message:
                        type: string
                      code:
                        enum:
                          - idempotency_conflict
                        type: string
                      type:
                        type: string
                      metadata:
                        required:
                          - provider_name
                        type: object
                        properties:
                          provider_name:
                            enum:
                              - FanifyHub
                            type: string
              example:
                error:
                  message: >-
                    This idempotency key was already used with a different
                    request.
                  code: idempotency_conflict
                  type: invalid_request_error
                  metadata:
                    provider_name: FanifyHub
        '429':
          description: OpenAI-compatible error.
          headers:
            Retry-After:
              description: Seconds before retrying.
              schema:
                type: string
          content:
            application/json:
              schema:
                required:
                  - error
                type: object
                properties:
                  error:
                    required:
                      - message
                      - code
                      - type
                      - metadata
                    type: object
                    properties:
                      message:
                        type: string
                      code:
                        enum:
                          - rate_limited
                        type: string
                      type:
                        type: string
                      metadata:
                        required:
                          - provider_name
                        type: object
                        properties:
                          provider_name:
                            enum:
                              - FanifyHub
                            type: string
              example:
                error:
                  message: Rate limit reached, retry later.
                  code: rate_limited
                  type: invalid_request_error
                  metadata:
                    provider_name: FanifyHub
        '503':
          description: OpenAI-compatible error.
          headers:
            Retry-After:
              description: Always 5 seconds for an in-progress replay.
              schema:
                type: string
          content:
            application/json:
              schema:
                required:
                  - error
                type: object
                properties:
                  error:
                    required:
                      - message
                      - code
                      - type
                      - metadata
                    type: object
                    properties:
                      message:
                        type: string
                      code:
                        enum:
                          - generation_in_progress
                          - provider_error
                        type: string
                      type:
                        type: string
                      metadata:
                        required:
                          - provider_name
                        type: object
                        properties:
                          provider_name:
                            enum:
                              - FanifyHub
                            type: string
              example:
                error:
                  message: A generation with this idempotency key is still in progress.
                  code: generation_in_progress
                  type: invalid_request_error
                  metadata:
                    provider_name: FanifyHub
      security:
        - Bearer: []
components:
  securitySchemes:
    Bearer:
      type: http
      description: Fanify API key.
      scheme: bearer
      bearerFormat: fanify_sk_...

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.