Skip to content

Streaming endpoints #36

@zamoshchin

Description

@zamoshchin

I'm getting a 502 (bad gateway) when calling my serverless function (API endpoint) that has a streaming response:

src/routes/api/soap/format.ts

...
export const POST: RequestHandler = async ({ request }) => {
  response = await openai.createChatCompletion({
      model: model,
      messages: [{ role: 'user', content: prompt }],
      stream: true,
    }, { responseType: 'stream' }
  );

  const customReadable = new ReadableStream({
    start(controller) {
      response.data.on('data', (data: Buffer) => {
        // ...etc
      });
    }
  });
  
  return new Response(customReadable, {
    headers: { 'Content-Type': 'text/html; charset=utf-8' },
  });
  ...

This works locally. Any idea what needs to be adjusted on CloudFront or Lambda to allow for streaming output?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions