Skip to content

Commit 391c3df

Browse files
authored
check helicone for inference (#5111)
1 parent 2c04889 commit 391c3df

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

worker/src/lib/ai-gateway/SimpleAIGateway.ts

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ import { Attempt, AttemptError, DisallowListEntry, EscrowInfo } from "./types";
1515
import { ant2oaiResponse } from "../clients/llmmapper/router/oai2ant/nonStream";
1616
import { ant2oaiStreamResponse } from "../clients/llmmapper/router/oai2ant/stream";
1717
import { validateOpenAIChatPayload } from "./validators/openaiRequestValidator";
18-
import { RequestParams, BodyMappingType } from "@helicone-package/cost/models/types";
18+
import {
19+
RequestParams,
20+
BodyMappingType,
21+
} from "@helicone-package/cost/models/types";
1922
import { SecureCacheProvider } from "../util/cache/secureCache";
2023
import { GatewayMetrics } from "./GatewayMetrics";
2124
import {
@@ -81,7 +84,8 @@ export class SimpleAIGateway {
8184

8285
const requestParams: RequestParams = {
8386
isStreaming: parsedBody.stream === true,
84-
bodyMapping: this.requestWrapper.heliconeHeaders.gatewayConfig.bodyMapping,
87+
bodyMapping:
88+
this.requestWrapper.heliconeHeaders.gatewayConfig.bodyMapping,
8589
};
8690

8791
let finalBody = parsedBody;
@@ -140,16 +144,26 @@ export class SimpleAIGateway {
140144
// Step 6: Try each attempt in order
141145
for (const attempt of attempts) {
142146
// temporarily disable Responses API calls for non-OpenAI endpoints
143-
if (this.requestWrapper.heliconeHeaders.gatewayConfig.bodyMapping === "RESPONSES" && attempt.endpoint.provider !== "openai") {
147+
if (
148+
this.requestWrapper.heliconeHeaders.gatewayConfig.bodyMapping ===
149+
"RESPONSES" &&
150+
attempt.endpoint.provider !== "openai" &&
151+
attempt.endpoint.provider !== "helicone"
152+
) {
144153
errors.push({
145154
source: attempt.source,
146-
message: "The Responses API is only supported for OpenAI provider endpoints.",
155+
message:
156+
"The Responses API is only supported for OpenAI provider endpoints.",
147157
type: "invalid_format",
148158
statusCode: 400,
149159
});
150160
continue;
151161
}
152-
if (attempt.authType === "ptb" && this.requestWrapper.heliconeHeaders.gatewayConfig.bodyMapping !== "NO_MAPPING") {
162+
if (
163+
attempt.authType === "ptb" &&
164+
this.requestWrapper.heliconeHeaders.gatewayConfig.bodyMapping !==
165+
"NO_MAPPING"
166+
) {
153167
const validationResult = validateOpenAIChatPayload(finalBody);
154168
if (isErr(validationResult)) {
155169
errors.push({
@@ -365,7 +379,9 @@ export class SimpleAIGateway {
365379

366380
const mappingType = attempt.endpoint.modelConfig.responseFormat ?? "OPENAI";
367381
const contentType = response.headers.get("content-type");
368-
const isStream = contentType?.includes("text/event-stream") || contentType?.includes("application/vnd.amazon.eventstream");
382+
const isStream =
383+
contentType?.includes("text/event-stream") ||
384+
contentType?.includes("application/vnd.amazon.eventstream");
369385

370386
try {
371387
if (mappingType === "OPENAI") {
@@ -446,7 +462,8 @@ export class SimpleAIGateway {
446462
e.type !== "disallowed"
447463
);
448464

449-
const all429 = errors.length > 0 && errors.every((e) => e.statusCode === 429);
465+
const all429 =
466+
errors.length > 0 && errors.every((e) => e.statusCode === 429);
450467

451468
if (first403) {
452469
statusCode = 403;
@@ -463,7 +480,9 @@ export class SimpleAIGateway {
463480
// - 401 (Unauthorized): User needs to fix API key
464481
// - 403 (Forbidden): Access denied
465482
// All other provider errors normalize to 500 for consistency
466-
const isActionableAuthError = firstNon429Error.statusCode === 401 || firstNon429Error.statusCode === 403;
483+
const isActionableAuthError =
484+
firstNon429Error.statusCode === 401 ||
485+
firstNon429Error.statusCode === 403;
467486
statusCode = isActionableAuthError ? firstNon429Error.statusCode : 500;
468487
message = firstNon429Error.message || "Request failed";
469488
code = "request_failed";

0 commit comments

Comments
 (0)