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

# Chat Completions (OpenAI Compatible)

An OpenAI-compatible endpoint that allows you to use CheckThat AI's claim normalization and fact-checking capabilities with existing OpenAI-style integrations and tools.

<Info>
  This endpoint follows the OpenAI Chat Completions API format, making it easy to integrate with existing applications and libraries designed for OpenAI's API.
</Info>

## Key Features

* **Drop-in replacement**: Compatible with OpenAI chat completion clients
* **Fact-checking enhanced**: Responses include claim analysis and verification
* **Streaming support**: Optional streaming responses for real-time interactions
* **Multiple models**: Support for various AI models through CheckThat AI

## Request Parameters

<ParamField body="api_key" type="string" required>
  Your CheckThat AI API key for authentication.
</ParamField>

<ParamField body="model" type="string" required>
  The model to use for generating responses. Use `/models` endpoint to see available options.
</ParamField>

<ParamField body="messages" type="array" required>
  Array of message objects representing the conversation history.

  <Expandable title="Message object format">
    <ResponseField name="role" type="string" required>
      The role of the message author. Must be one of: "system", "user", or "assistant".
    </ResponseField>

    <ResponseField name="content" type="string" required>
      The content of the message.
    </ResponseField>
  </Expandable>
</ParamField>

<ParamField body="stream" type="boolean" default="false">
  Whether to stream the response back as it's generated. Set to `true` for real-time streaming.
</ParamField>

<ParamField body="temperature" type="number">
  Controls randomness in the response. Lower values make output more focused and deterministic. Range: 0.0 to 2.0.
</ParamField>

<ParamField body="top_p" type="number">
  Alternative to temperature. Controls diversity via nucleus sampling. Range: 0.0 to 1.0.
</ParamField>

<ParamField body="max_tokens" type="integer">
  Maximum number of tokens to generate in the response.
</ParamField>

## Request Examples

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST 'https://api.checkthat-ai.com/v1/chat/completions' \
    -H 'Content-Type: application/json' \
    -d '{
      "api_key": "YOUR_API_KEY",
      "model": "gpt-4",
      "messages": [
        {
          "role": "system",
          "content": "You are a fact-checking assistant specialized in claim verification."
        },
        {
          "role": "user", 
          "content": "Is it true that vaccines cause autism?"
        }
      ],
      "temperature": 0.3,
      "max_tokens": 1000
    }'
  ```
</RequestExample>

<RequestExample>
  ```javascript JavaScript (using OpenAI library) theme={null}
  import OpenAI from 'openai';

  const client = new OpenAI({
    apiKey: 'YOUR_CHECKTHAT_API_KEY',
    baseURL: 'https://api.checkthat-ai.com/v1'
  });

  const completion = await client.chat.completions.create({
    model: 'gpt-4',
    messages: [
      {
        role: 'user',
        content: 'Fact-check this claim: Coffee consumption prevents diabetes'
      }
    ],
    temperature: 0.1,
    max_tokens: 800
  });

  console.log(completion.choices[0].message.content);
  ```
</RequestExample>

<RequestExample>
  ```python Python (using OpenAI library) theme={null}
  from openai import OpenAI

  client = OpenAI(
      api_key="YOUR_CHECKTHAT_API_KEY",
      base_url="https://api.checkthat-ai.com/v1"
  )

  response = client.chat.completions.create(
      model="gpt-4",
      messages=[
          {"role": "system", "content": "You are a fact-checking expert."},
          {"role": "user", "content": "Evaluate this claim: 5G networks cause cancer"}
      ],
      temperature=0.2,
      max_tokens=1200
  )

  print(response.choices[0].message.content)
  ```
</RequestExample>

## Response Format

### Standard Response

<ResponseExample>
  ```json Success Response theme={null}
  {
    "id": "chatcmpl-123abc", 
    "object": "chat.completion",
    "created": 1694268190,
    "model": "gpt-4",
    "choices": [
      {
        "index": 0,
        "message": {
          "role": "assistant",
          "content": "Based on extensive scientific research and multiple systematic reviews..."
        },
        "finish_reason": "stop"
      }
    ],
    "usage": {
      "prompt_tokens": 45,
      "completion_tokens": 234,
      "total_tokens": 279
    },
    "fact_check_metadata": {
      "claims_detected": 1,
      "confidence_score": 0.92,
      "sources_consulted": ["WHO", "CDC", "peer_reviewed_studies"]
    }
  }
  ```
</ResponseExample>

### Streaming Response

When `stream: true` is set, responses are sent as Server-Sent Events:

<ResponseExample>
  ```text Streaming Response theme={null}
  data: {"id":"chatcmpl-123","choices":[{"delta":{"content":"Based"}}]}

  data: {"id":"chatcmpl-123","choices":[{"delta":{"content":" on"}}]}

  data: {"id":"chatcmpl-123","choices":[{"delta":{"content":" scientific"}}]}

  data: [DONE]
  ```
</ResponseExample>

## Response Fields

<ResponseField name="id" type="string" required>
  Unique identifier for the chat completion response.
</ResponseField>

<ResponseField name="object" type="string" required>
  Object type, always "chat.completion" for this endpoint.
</ResponseField>

<ResponseField name="created" type="integer" required>
  Unix timestamp of when the completion was created.
</ResponseField>

<ResponseField name="model" type="string" required>
  The model used for generating the completion.
</ResponseField>

<ResponseField name="choices" type="array" required>
  Array of completion choices (typically contains one choice).

  <Expandable title="Choice object properties">
    <ResponseField name="index" type="integer">
      Index of this choice in the choices array.
    </ResponseField>

    <ResponseField name="message" type="object">
      The generated message content.
    </ResponseField>

    <ResponseField name="finish_reason" type="string">
      Reason why generation stopped: "stop", "length", or "content\_filter".
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="usage" type="object">
  Token usage statistics for the request.

  <Expandable title="Usage statistics">
    <ResponseField name="prompt_tokens" type="integer">
      Number of tokens in the input prompt.
    </ResponseField>

    <ResponseField name="completion_tokens" type="integer">
      Number of tokens in the generated completion.
    </ResponseField>

    <ResponseField name="total_tokens" type="integer">
      Total tokens used (prompt + completion).
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="fact_check_metadata" type="object">
  CheckThat AI specific metadata about claim analysis (unique to our platform).

  <Expandable title="Fact-checking metadata">
    <ResponseField name="claims_detected" type="integer">
      Number of factual claims identified in the conversation.
    </ResponseField>

    <ResponseField name="confidence_score" type="number">
      Confidence level in the fact-checking analysis (0.0 to 1.0).
    </ResponseField>

    <ResponseField name="sources_consulted" type="array">
      List of authoritative sources referenced during fact-checking.
    </ResponseField>
  </Expandable>
</ResponseField>

## Integration Benefits

<CardGroup cols={2}>
  <Card title="Easy Migration" icon="arrows-rotate">
    Drop-in replacement for OpenAI API calls in existing applications
  </Card>

  <Card title="Enhanced Output" icon="shield-check">
    All responses include fact-checking analysis and source verification
  </Card>

  <Card title="Library Support" icon="code">
    Works with popular OpenAI client libraries without modification
  </Card>

  <Card title="Streaming Support" icon="wifi">
    Real-time streaming for interactive applications and chatbots
  </Card>
</CardGroup>

<Warning>
  Remember to use your CheckThat AI API key, not your OpenAI key, and set the correct base URL when configuring OpenAI client libraries.
</Warning>


## OpenAPI

````yaml POST /v1/chat/completions
openapi: 3.1.0
info:
  title: CheckThat AI - Advanced Claim Normalization & Fact-Checking Platform
  description: API for the CheckThat AI Platform - https://www.checkthat-ai.com
  version: 1.0.0
servers: []
security: []
paths:
  /v1/chat/completions:
    post:
      tags:
        - /chat/completions
      summary: Chat Completions
      operationId: chat_completions_v1_chat_completions_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatCompletionsRequest'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema: {}
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    ChatCompletionsRequest:
      properties:
        api_key:
          type: string
          title: Api Key
        model:
          type: string
          title: Model
        messages:
          items:
            $ref: '#/components/schemas/OpenAIChatMessage'
          type: array
          title: Messages
        stream:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Stream
          default: false
        temperature:
          anyOf:
            - type: number
            - type: 'null'
          title: Temperature
        top_p:
          anyOf:
            - type: number
            - type: 'null'
          title: Top P
        max_tokens:
          anyOf:
            - type: integer
            - type: 'null'
          title: Max Tokens
      type: object
      required:
        - api_key
        - model
        - messages
      title: ChatCompletionsRequest
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    OpenAIChatMessage:
      properties:
        role:
          type: string
          enum:
            - system
            - user
            - assistant
          title: Role
        content:
          type: string
          title: Content
      type: object
      required:
        - role
        - content
      title: OpenAIChatMessage
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError

````