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

# Chat Completions

Generate chat completions with optional search augmentation.

<ParamFields />

## Example Request

```bash theme={null}
curl -X POST https://api.agentserp.com/chat/completions \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{"model": "gpt-4o-mini", "messages": [{"role": "user", "content": "Hello, who are you?"}]}'
```


## OpenAPI

````yaml POST /chat/completions
openapi: 3.0.0
info:
  title: AgentSerp API
  version: 1.0.0
  description: API for search, extraction, summarization, and more.
servers:
  - url: https://906e-2001-5a8-6cc-e000-55c0-f0b-9da7-10b0.ngrok-free.app
    description: AgentSerp API
security: []
paths:
  /chat/completions:
    post:
      summary: Chat completions
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                model:
                  type: string
                  description: LLM engine to use
                messages:
                  type: array
                  items:
                    type: object
                    properties:
                      role:
                        type: string
                        enum:
                          - system
                          - user
                          - assistant
                          - tool
                        description: OpenAI-style chat roles
                      content:
                        type: string
                    required:
                      - role
                      - content
                    description: Single chat message
                  minItems: 1
                search:
                  type: object
                  properties:
                    domain_filter:
                      type: array
                      items:
                        type: string
                      description: Allowed hostnames while augmenting answer
                    recency:
                      anyOf:
                        - type: string
                          enum:
                            - day
                            - week
                            - month
                            - year
                          description: Human shortcut for common recency windows
                        - type: integer
                          minimum: 0
                          exclusiveMinimum: true
                      description: Recency constraint for on-the-fly search
                  description: Optional search-control block for chat
                stream:
                  type: boolean
                  description: If true, SSE stream; else aggregate JSON
                user_context:
                  type: object
                  additionalProperties:
                    nullable: true
                  description: Opaque dict preserved across turns
              required:
                - model
                - messages
              description: Input for POST /chat/completions
      responses:
        '200':
          description: Chat response
          content:
            application/json:
              schema:
                type: object
                properties:
                  request_id:
                    type: string
                    description: Echo of client-supplied ID or server-assigned UUID
                  data:
                    type: object
                    properties:
                      choices:
                        type: array
                        items:
                          type: object
                          properties:
                            index:
                              type: integer
                            message:
                              type: object
                              properties:
                                role:
                                  type: string
                                  enum:
                                    - system
                                    - user
                                    - assistant
                                    - tool
                                  description: OpenAI-style chat roles
                                content:
                                  type: string
                              required:
                                - role
                                - content
                              description: Single chat message
                          required:
                            - index
                            - message
                          description: One completion option
                    required:
                      - choices
                    description: Endpoint-specific payload
                  meta:
                    type: object
                    properties:
                      api_version:
                        type: string
                        description: >-
                          Semantic version string of the API that produced the
                          response
                      processing_ms:
                        type: integer
                        description: Time taken on the server to satisfy the request, in ms
                      tokens_used:
                        type: integer
                        description: Total LLM tokens consumed (prompt+completion)
                      cost:
                        type: object
                        properties:
                          total:
                            type: number
                            minimum: 0
                            description: Total dollar cost for serving this request
                          breakdown:
                            type: object
                            additionalProperties:
                              type: number
                              minimum: 0
                            description: >-
                              Optional map of operation → incremental cost (e.g.
                              neuralSearch: 0.004)
                        required:
                          - total
                        description: Per-request cost information
                    required:
                      - api_version
                    description: Metadata block attached to every response
                required:
                  - data
                description: Universal response wrapper
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                required:
                  - error

````