Skip to content

add check for openai stainless streaming header #172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/proxy/src/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ export const CACHED_HEADER = "x-bt-cached";

export const USED_ENDPOINT_HEADER = "x-bt-used-endpoint";

export const OAI_STAINLESS_METHOD_HEADER = "x-stainless-helper-method";

const CACHE_MODES = ["auto", "always", "never"] as const;

// Options to control how the cache key is generated.
Expand Down Expand Up @@ -334,6 +336,13 @@ export async function proxyV1({

let startTime = getCurrentUnixTimestamp();
let spanType: SpanType | undefined = undefined;
// TEMP: support OAI streaming via oai.beta.chat.completions.stream
// openai-node currently overrides the usual stream param to false
const isStainlessStream =
proxyHeaders[OAI_STAINLESS_METHOD_HEADER] === "stream";
if (isStainlessStream && bodyData) {
bodyData.stream = true;
}
const isStreaming = !!bodyData?.stream;

let stream: ReadableStream<Uint8Array> | null = null;
Expand Down