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

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: 4a0a004730450221008fb4d8872899a8e9448961c305da17e034244c08eaf0df22c01260b3fc8b7a4d022052f9b90015be91b811d8aac84443c3b4fda82d36520b4406218db80c36f308e7:922c64590222798bb761d5b6d8e72950