> ## Documentation Index
> Fetch the complete documentation index at: https://test-62a57ffd.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Chat completion



## OpenAPI

````yaml api-reference/openapi.json post /v1/chat/completions
openapi: 3.1.0
info:
  title: Brave Search Products API
  description: |

    Product APIs exposed by Brave Search.

    You will be able to:

    * **Web Search**
  termsOfService: http://localhost:10000/terms-of-use/
  contact:
    name: Brave Search API
    url: http://localhost:10000/contact/
    email: search-api@brave.com
  license:
    name: Apache 2.0
    url: https://www.apache.org/licenses/LICENSE-2.0.html
  version: 1.0.0
  x-logo:
    url: >-
      https://cdn.search.brave.com/docs/681607ea86f83e9e04d242342a18f73f83f37137f5cd5246753f7a7a5beaca32-brave-logo-home-dark.svg
servers:
  - url: /res
    description: Default server
security:
  - ApiKeyAuth: []
tags:
  - name: web
    description: Get search results from the web
    x-displayName: Web Search
    x-mint:
      title: Web Search API
      description: Get search results from the web
  - name: news
    description: Get search results from the news
    x-displayName: News Search
  - name: videos
    description: Get search results from the videos
    x-displayName: Videos Search
  - name: images
    description: Get search results from the images
    x-displayName: Images Search
  - name: summarizer
    description: Get summarized search results
    x-displayName: AI Search
  - name: other
    description: Other API services
    x-displayName: Other
paths:
  /v1/chat/completions:
    post:
      tags:
        - summarizer
      summary: Chat completion
      operationId: openai_chat_completion_v1_chat_completions_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/OpenAIChatRequest'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OpenAIChatResponse'
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                OPTION_NOT_IN_PLAN:
                  summary: Option not in plan.
                  value:
                    type: ErrorResponse
                    errors:
                      - id: 5d832250-9396-4f6e-b84a-2a1fe524cd7d
                        code: OPTION_NOT_IN_PLAN
                        detail: The option is not subscribed in the plan.
                        status: 400
                        meta:
                          component: authentication
                    time: 1663072993
          description: Bad Request
        '402':
          description: Payment Required
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                USAGE_LIMIT_EXCEEDED:
                  summary: Usage limit exceeded.
                  value:
                    type: ErrorResponse
                    errors:
                      - id: 5d832250-9396-4f6e-b84a-2a1fe524cd7d
                        code: USAGE_LIMIT_EXCEEDED
                        detail: Usage limit exceeded.
                        status: 402
                        meta:
                          component: api
                    time: 1663072993
        '403':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                RESOURCE_NOT_ALLOWED:
                  summary: Resource not allowed.
                  value:
                    type: ErrorResponse
                    errors:
                      - id: 5d832250-9396-4f6e-b84a-2a1fe524cd7d
                        code: RESOURCE_NOT_ALLOWED
                        detail: The user is not authorized to access this resource.
                        status: 403
                        meta:
                          component: api
                    time: 1663072993
          description: Forbidden
        '404':
          content:
            application/json:
              examples:
                SUBSCRIPTION_NOT_FOUND:
                  summary: Missing subscription.
                  value:
                    type: ErrorResponse
                    errors:
                      - id: 5d832250-9396-4f6e-b84a-2a1fe524cd7d
                        code: SUBSCRIPTION_NOT_FOUND
                        detail: No subscription found.
                        status: 404
                        meta:
                          component: subscriptions
                    time: 1663072993
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Not Found
        '422':
          content:
            application/json:
              examples:
                SUBSCRIPTION_TOKEN_INVALID:
                  summary: Invalid subscription token.
                  value:
                    type: ErrorResponse
                    errors:
                      - id: 5d832250-9396-4f6e-b84a-2a1fe524cd7d
                        code: SUBSCRIPTION_TOKEN_INVALID
                        detail: The provided subscription token is invalid.
                        status: 422
                        meta:
                          component: authentication
                    time: 1663072993
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Unprocessable Entity
        '429':
          content:
            application/json:
              examples:
                RATE_LIMITED:
                  summary: Rate limited.
                  value:
                    type: ErrorResponse
                    errors:
                      - id: 5d832250-9396-4f6e-b84a-2a1fe524cd7d
                        code: RATE_LIMITED
                        detail: Request rate limit exceeded for plan.
                        status: 429
                        meta:
                          component: rate_limiter
                    time: 1663072993
                QUOTA_LIMITED:
                  summary: Quota limited.
                  value:
                    type: ErrorResponse
                    errors:
                      - id: 5d832250-9396-4f6e-b84a-2a1fe524cd7d
                        code: QUOTA_LIMITED
                        detail: Request quota limit exceeded for plan.
                        status: 429
                        meta:
                          component: rate_limiter
                    time: 1663072993
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Too Many Requests
components:
  schemas:
    OpenAIChatRequest:
      properties:
        messages:
          items:
            $ref: '#/components/schemas/UserMessage'
          type: array
          maxItems: 1
          minItems: 1
          title: Messages
        model:
          type: string
          enum:
            - brave-pro
            - brave
          title: Model
          default: brave-pro
        max_completion_tokens:
          anyOf:
            - type: integer
            - type: 'null'
          title: Max Completion Tokens
        metadata:
          anyOf:
            - additionalProperties:
                type: string
              type: object
            - type: 'null'
          title: Metadata
        seed:
          anyOf:
            - type: integer
            - type: 'null'
          title: Seed
        stream:
          type: boolean
          title: Stream
          default: true
        web_search_options:
          anyOf:
            - $ref: '#/components/schemas/WebSearchOptions'
            - type: 'null'
        country:
          type: string
          title: Country
          default: us
        language:
          type: string
          title: Language
          default: en
        safesearch:
          type: string
          title: Safesearch
          default: moderate
        enable_entities:
          type: boolean
          title: Enable Entities
          default: false
        enable_citations:
          type: boolean
          title: Enable Citations
          default: false
        enable_research:
          type: boolean
          title: Enable Research
          default: false
        research_allow_thinking:
          type: boolean
          title: Research Allow Thinking
          default: true
        research_maximum_number_of_tokens_per_query:
          type: integer
          maximum: 16384
          minimum: 1024
          title: Research Maximum Number Of Tokens Per Query
          default: 8192
        research_maximum_number_of_queries:
          type: integer
          maximum: 50
          minimum: 1
          title: Research Maximum Number Of Queries
          default: 20
        research_maximum_number_of_iterations:
          type: integer
          maximum: 5
          minimum: 1
          title: Research Maximum Number Of Iterations
          default: 4
        research_maximum_number_of_seconds:
          type: integer
          maximum: 300
          minimum: 1
          title: Research Maximum Number Of Seconds
          default: 180
        research_maximum_number_of_results_per_query:
          type: integer
          maximum: 60
          minimum: 1
          title: Research Maximum Number Of Results Per Query
          default: 60
      type: object
      required:
        - messages
      title: OpenAIChatRequest
    OpenAIChatResponse:
      properties:
        model:
          type: string
          enum:
            - brave-pro
            - brave
          title: Model
          default: brave-pro
        system_fingerprint:
          anyOf:
            - type: string
            - type: 'null'
          title: System Fingerprint
        choices:
          items:
            $ref: '#/components/schemas/ChoiceChunk'
          type: array
          title: Choices
        created:
          type: integer
          title: Created
        id:
          type: string
          title: Id
        object:
          type: string
          enum:
            - chat.completion.chunk
          const: chat.completion.chunk
          title: Object
          default: chat.completion.chunk
        usage:
          anyOf:
            - $ref: '#/components/schemas/OpenAIUsage'
            - type: 'null'
      type: object
      required:
        - choices
        - created
        - id
      title: OpenAIChatResponse
    ErrorResponse:
      properties:
        type:
          type: string
          title: Type
          default: ErrorResponse
        error:
          $ref: '#/components/schemas/ErrorModel'
        time:
          type: integer
          title: Time
          default: 0
      type: object
      required:
        - error
      title: ErrorResponse
    UserMessage:
      properties:
        role:
          type: string
          enum:
            - user
          const: user
          title: Role
          default: user
        content:
          type: string
          title: Content
      type: object
      required:
        - content
      title: UserMessage
    WebSearchOptions:
      properties:
        search_context_size:
          anyOf:
            - type: string
              enum:
                - low
                - medium
                - high
            - type: 'null'
          title: Search Context Size
        user_location:
          anyOf:
            - $ref: '#/components/schemas/UserLocation'
            - type: 'null'
      type: object
      title: WebSearchOptions
    ChoiceChunk:
      properties:
        delta:
          $ref: '#/components/schemas/Delta'
        finish_reason:
          anyOf:
            - type: string
              enum:
                - stop
                - length
            - type: 'null'
          title: Finish Reason
      type: object
      required:
        - delta
      title: ChoiceChunk
    OpenAIUsage:
      properties:
        completion_tokens:
          type: integer
          title: Completion Tokens
        prompt_tokens:
          type: integer
          title: Prompt Tokens
        total_tokens:
          type: integer
          title: Total Tokens
        completion_tokens_details:
          anyOf:
            - $ref: '#/components/schemas/OpenAICompletionTokensDetails'
            - type: 'null'
      type: object
      required:
        - completion_tokens
        - prompt_tokens
        - total_tokens
      title: OpenAIUsage
    ErrorModel:
      properties:
        id:
          type: string
          title: Id
        status:
          type: integer
          title: Status
        code:
          $ref: '#/components/schemas/ErrorCode'
        detail:
          anyOf:
            - type: string
            - type: 'null'
          title: Detail
        meta:
          anyOf:
            - type: object
            - type: 'null'
          title: Meta
      type: object
      required:
        - id
        - status
        - code
      title: ErrorModel
    UserLocation:
      properties:
        approximate:
          $ref: '#/components/schemas/ApproximateUserLocation'
        type:
          type: string
          enum:
            - approximate
          const: approximate
          title: Type
          default: approximate
      type: object
      required:
        - approximate
      title: UserLocation
    Delta:
      properties:
        role:
          type: string
          enum:
            - assistant
          const: assistant
          title: Role
          default: assistant
        content:
          type: string
          title: Content
      type: object
      required:
        - content
      title: Delta
    OpenAICompletionTokensDetails:
      properties:
        reasoning_tokens:
          anyOf:
            - type: integer
            - type: 'null'
          title: Reasoning Tokens
      type: object
      title: OpenAICompletionTokensDetails
    ErrorCode:
      type: string
      enum:
        - INTERNAL
        - INVALID_ID
        - UNAUTHORIZED
        - RESOURCE_NOT_ALLOWED
        - FORBIDDEN
        - VALIDATION
        - INVALID_PASSWORD
        - INVALID_EMAIL
        - INVALID_NAME
        - INVALID_COMPANY
        - INVALID_VAT_NUMBER
        - INVALID_DESCRIPTION
        - INVALID_USAGE
        - INVALID_INVOICE_NOTES
        - INVALID_PURCHASE_ORDER
        - PASSWORD_REUSED
        - PASSWORD_BREACHED
        - INVALID_TIME_RANGE
        - USER_ALREADY_EXISTS
        - USER_INACTIVE
        - RESET_PASSWORD_BAD_TOKEN
        - USER_NOT_FOUND
        - LOGIN_BAD_CREDENTIALS
        - LOGIN_USER_LOCKED_OUT
        - LOGIN_USER_NOT_VERIFIED
        - LOGIN_INVALID_MFA_CHALLENGE
        - VERIFY_USER_BAD_TOKEN
        - VERIFY_USER_ALREADY_VERIFIED
        - PLAN_NOT_FOUND
        - PLAN_ALREADY_EXISTS
        - PLAN_ALREADY_PUBLIC
        - PLAN_ALREADY_ALLOWED
        - STRIPE_CUSTOMER_NOT_EXISTS
        - STRIPE_SUBSCRIPTION_NOT_EXISTS
        - PRODUCT_NOT_FOUND
        - API_VERSION_NOT_FOUND
        - PRODUCT_ALREADY_EXISTS
        - OPTION_NOT_FOUND
        - OPTION_ALREADY_EXISTS
        - OPTION_NOT_IN_PLAN
        - SUBSCRIPTION_TOKEN_LIMIT
        - SUBSCRIPTION_TOKEN_INVALID
        - SUBSCRIPTION_TOKEN_INACTIVE
        - SUBSCRIPTION_TOKEN_DEACTIVATED
        - SUBSCRIPTION_TOKEN_NOT_FOUND
        - SUBSCRIPTION_ALREADY_EXISTS
        - SUBSCRIPTION_NOT_FOUND
        - ACTIVITY_SESSION_NOT_FOUND
        - ORGANIZATION_NOT_FOUND
        - ORGANIZATION_NOT_MEMBER
        - NO_PLANS_SUBSCRIBED
        - QUOTA_LIMITED
        - RATE_LIMITED
        - USAGE_LIMIT_EXCEEDED
        - USAGE_LIMIT_NOT_FOUND
        - USAGE_LIMIT_ALREADY_EXISTS
        - RESOURCE_NOT_SUBSCRIBED
        - CONTENT_TYPE_NOT_SUPPORTED
        - AGGREGATION_NOT_SUPPORTED
        - TIME_GRANULARITY_NOT_SUPPORTED
        - CURRENCY_NOT_FOUND
        - CURRENCY_ALREADY_EXISTS
        - CSRF_VERIFICATION
        - INVALID_GOGGLE_URL
        - INVALID_URL
        - INVALID_DOMAIN
        - INVALID_RESULT_FILTER
        - CONTENT_URL_LIMIT_EXCEEDED
        - TOS_NOT_FOUND
        - ADDENDUM_NOT_FOUND
        - REDACTION_NOT_FOUND
        - REDACTION_ALREADY_EXISTS
        - ADDENDUM_ALREADY_EXISTS
        - TOS_ALREADY_EXISTS
        - QUERY_NOT_FOUND
        - EMAIL_DOMAIN_IN_BLOCKLIST_NOT_FOUND
        - EMAIL_DOMAIN_IN_BLOCKLIST_ALREADY_EXISTS
        - EMAIL_DOMAIN_NOT_ALLOWED
        - INVALID_TOTP_TOKEN
        - EMAIL_MFA_SENT_EXCEEDED
        - EMAIL_MFA_NOT_SENT
        - AUTHENTICATOR_MFA_ALREADY_EXISTS
        - AUTHENTICATOR_MFA_NOT_FOUND
        - MFA_FAIL_TOO_MANY_ATTEMPTS
        - INVALID_RECOVERY_CODE
        - MFA_TOKEN_NOT_FOUND
        - PAYMENT_METHOD_NOT_FOUND
        - PAYMENT_METHOD_ALREADY_EXISTS
        - ROLE_NOT_FOUND
        - USER_ALREADY_MEMBER
        - ORGANIZATION_INVITATION_ALREADY_EXISTS
        - INVALID_ORGANIZATION_INVITATION
        - ORGANIZATION_INVITATION_NOT_FOUND
        - COMPLIANCE_NOT_FOUND
        - AWS_MARKETPLACE_TOKEN_INVALID
        - AWS_MARKETPLACE_TOKEN_EXPIRED
        - AWS_MARKETPLACE_CUSTOMER_RESOLUTION_FAILED
        - AWS_MARKETPLACE_PRODUCT_NOT_FOUND
        - AWS_MARKETPLACE_CREDENTIALS_MISSING
        - AWS_MARKETPLACE_API_ERROR
        - EMAIL_CHANGE_BAD_TOKEN
        - EMAIL_CHANGE_INVALID_MFA_CHALLENGE
        - EMAIL_CHANGE_MFA_FAIL_TOO_MANY_ATTEMPTS
        - EMAIL_CHANGE_RATE_LIMITED
        - EMAIL_CHANGE_INVALID_PASSWORD
      title: ErrorCode
    ApproximateUserLocation:
      properties:
        city:
          anyOf:
            - type: string
            - type: 'null'
          title: City
        country:
          anyOf:
            - type: string
            - type: 'null'
          title: Country
        region:
          anyOf:
            - type: string
            - type: 'null'
          title: Region
        timezone:
          anyOf:
            - type: string
            - type: 'null'
          title: Timezone
      type: object
      title: ApproximateUserLocation
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-subscription-token
      description: The subscription token that was generated for the product.

````