id: api-openai

info:
  name: OpenAI API Test
  author: geeknik
  severity: info
  reference:
    - https://platform.openai.com/docs/api-reference
  metadata:
    verified: true
    max-request: 1
  tags: token-spray,openai,ai

self-contained: true

http:
  - method: POST
    path:
      - "https://api.openai.com/v1/chat/completions"
    body: |
      {
        "model": "gpt-3.5-turbo",
        "messages": [
          {"role": "system", "content": "You are a helpful assistant designed to output JSON."},
          {"role": "user", "content": "Who won the world series in 2020?"}
        ]
      }

    headers:
      Content-Type: application/json
      Authorization: Bearer {{token}}

    matchers-condition: and
    matchers:
      - type: word
        part: body
        words:
          - 'Los Angeles Dodgers'
      - type: word
        part: body
        words:
          - 'invalid_request_error'
          - 'Incorrect API key'
          - 'invalid_api_key'
        condition: or
        negative: true
# digest: 4a0a0047304502203477775d01a523f90d41a2afb63ab4ddc5b2a1acd762b1fcc46c13a0d50fd55f022100e896fbf5886033b9e3b4490c6e6e3e4dd730b14d166d03940b607cee3e0c1121:922c64590222798bb761d5b6d8e72950