Skip to content
Closed
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion open-sse/handlers/chatCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ export async function handleChatCore({ body, modelInfo, credentials, log, onCred
})();
const reqTag = log?.tagForSession ? log.tagForSession(sessionSeed) : (log?.nextTag ? log.nextTag() : "");

const sourceFormat = sourceFormatOverride || detectFormat(body);
// Format resolution: Override > Endpoint > Body-based
const sourceFormat = sourceFormatOverride || (clientRawRequest?.endpoint?.includes("/messages") ? FORMATS.CLAUDE : detectFormat(body));

// Check for bypass patterns (warmup, skip, cc naming)
const bypassResponse = handleBypassRequest(body, model, userAgent, ccFilterNaming);
Expand Down
2 changes: 1 addition & 1 deletion open-sse/services/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export function detectFormat(body) {

// If content is string, it's likely OpenAI (Claude also supports this)
// Check for other Claude-specific indicators
if (body.system !== undefined || body.anthropic_version) {
if (body.system !== undefined || body.anthropic_version || body['anthropic-version']) {
return "claude";
}
}
Expand Down
5 changes: 3 additions & 2 deletions open-sse/translator/formats.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ export const FORMATS = {
* Returns null to fall back to body-based detection.
*/
export function detectFormatByEndpoint(pathname, body) {
if (!pathname) return null;
// /v1/responses is always openai-responses
if (pathname.includes("/v1/responses")) return FORMATS.OPENAI_RESPONSES;

// /v1/messages is always Claude
if (pathname.includes("/v1/messages")) return FORMATS.CLAUDE;
// /v1/messages or /messages is always Claude
if (pathname.includes("/v1/messages") || pathname.includes("/messages")) return FORMATS.CLAUDE;

// /v1/chat/completions + input[] → treat as openai (Cursor CLI sends Responses body via chat endpoint)
if (pathname.includes("/v1/chat/completions") && Array.isArray(body?.input)) {
Expand Down
5 changes: 3 additions & 2 deletions src/sse/handlers/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,9 @@ async function handleSingleModelChat(body, modelStr, clientRawRequest = null, re
pxpipeTransform: chatSettings.pxpipeEnabled ? await getPxpipeTransform() : null,
onPxpipeEvent: appendPxpipeEvent,
providerThinking,
// Detect source format by endpoint + body
sourceFormatOverride: request?.url ? detectFormatByEndpoint(new URL(request.url).pathname, body) : null,
sourceFormatOverride: (clientRawRequest?.endpoint || request?.url)
? detectFormatByEndpoint(clientRawRequest?.endpoint || (request?.url?.startsWith("http") ? new URL(request.url).pathname : request?.url || ""), body)
: null,
onCredentialsRefreshed: async (newCreds) => {
await updateProviderCredentials(credentials.connectionId, {
...newCreds,
Expand Down