HTTPSSEClient icon indicating copy to clipboard operation
HTTPSSEClient copied to clipboard

Support making an arbitrary HTTP request that returns an event stream

Open 3ddelano opened this issue 10 months ago • 0 comments

It would be nice if the plugin can support making an arbitrary HTTP request which returns an event stream response instead of just making a GET request to / in the attempt_to_request() method.

Example:

POST https://api.openai.com/v1/chat/completions

with headers

[
  "Content-Type: application/json",
  "Authorization: Bearer <token here>"
]

with body

{
  "stream": true,
  "messages": [{"role": "user", "content": "what is godot engine"}],
  "model": "gpt-4o-mini"
}

Proposed api:

func request(url: String, custom_headers = [], method = HTTPClient.METHOD_GET, body = ""): Error func request_raw(url: String, custom_headers = [], method = HTTPClient.METHOD_GET, body_raw =PackedByteArray()): Error

Example usage:

var sse = HTTPSSEClient.new()
sse.new_sse_event.connect(_on_new_sse_event)
var err = sse.request(...)
if err != OK:
    printerr("Failed to send request error=%s" % err)

3ddelano avatar Mar 07 '25 11:03 3ddelano