Skip to content
Merged
2 changes: 1 addition & 1 deletion ci/platform-matrix.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"name": "Other OpenAI-compatible endpoint",
"status": "caveated",
"endpoint_type": "Custom OpenAI-compatible",
"notes": "Adapter path validated against OpenRouter as the `compatible-endpoint` provider with `openrouter/auto` (see `src/lib/inference/config.test.ts:119`); the onboarding prompt that surfaces OpenRouter as the worked example is in `handleRemoteProviderSelection` in `src/lib/onboard.ts`. Behavior on other OpenAI-compatible proxies, gateways, and self-hosted implementations may vary; this row claims the adapter, not the universe of compatible endpoints."
"notes": "Adapter path validated against OpenRouter as the `compatible-endpoint` provider with `openrouter/auto` (see `src/lib/inference/config.test.ts:120`); the onboarding prompt that surfaces OpenRouter as the worked example is in `handleRemoteProviderSelection` in `src/lib/onboard.ts`. Behavior on other OpenAI-compatible proxies, gateways, and self-hosted implementations may vary; this row claims the adapter, not the universe of compatible endpoints."
},
{
"name": "Anthropic",
Expand Down
2 changes: 1 addition & 1 deletion docs/inference/inference-options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ NemoClaw uses provider-specific local tokens for those routes, and rebuilds of l
|----------|--------|---------------|-------|
| NVIDIA Endpoints | Tested | OpenAI-compatible | Hosted models on integrate.api.nvidia.com |
| OpenAI | Tested | Native OpenAI-compatible | Uses OpenAI model IDs |
| Other OpenAI-compatible endpoint | Tested with limitations | Custom OpenAI-compatible | Adapter path validated against OpenRouter as the `compatible-endpoint` provider with `openrouter/auto` (see `src/lib/inference/config.test.ts:119`); the onboarding prompt that surfaces OpenRouter as the worked example is in `handleRemoteProviderSelection` in `src/lib/onboard.ts`. Behavior on other OpenAI-compatible proxies, gateways, and self-hosted implementations may vary; this row claims the adapter, not the universe of compatible endpoints. |
| Other OpenAI-compatible endpoint | Tested with limitations | Custom OpenAI-compatible | Adapter path validated against OpenRouter as the `compatible-endpoint` provider with `openrouter/auto` (see `src/lib/inference/config.test.ts:120`); the onboarding prompt that surfaces OpenRouter as the worked example is in `handleRemoteProviderSelection` in `src/lib/onboard.ts`. Behavior on other OpenAI-compatible proxies, gateways, and self-hosted implementations may vary; this row claims the adapter, not the universe of compatible endpoints. |
| Anthropic | Tested | Native Anthropic | Uses anthropic-messages |
| Other Anthropic-compatible endpoint | Tested with limitations | Custom Anthropic-compatible | Adapter path validated with AWS Bedrock (`src/lib/onboard/bedrock-runtime.ts`). Behavior on other Anthropic-compatible proxies and gateways may vary; this row claims the adapter, not the universe of compatible endpoints. |
| Google Gemini | Tested | OpenAI-compatible | Uses Google's OpenAI-compatible endpoint |
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/platform-support.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ NemoClaw routes inference through the OpenShell gateway. Each row below is a pro
|----------|--------|---------------|-------|
| NVIDIA Endpoints | Tested | OpenAI-compatible | Hosted models on integrate.api.nvidia.com |
| OpenAI | Tested | Native OpenAI-compatible | Uses OpenAI model IDs |
| Other OpenAI-compatible endpoint | Tested with limitations | Custom OpenAI-compatible | Adapter path validated against OpenRouter as the `compatible-endpoint` provider with `openrouter/auto` (see `src/lib/inference/config.test.ts:119`); the onboarding prompt that surfaces OpenRouter as the worked example is in `handleRemoteProviderSelection` in `src/lib/onboard.ts`. Behavior on other OpenAI-compatible proxies, gateways, and self-hosted implementations may vary; this row claims the adapter, not the universe of compatible endpoints. |
| Other OpenAI-compatible endpoint | Tested with limitations | Custom OpenAI-compatible | Adapter path validated against OpenRouter as the `compatible-endpoint` provider with `openrouter/auto` (see `src/lib/inference/config.test.ts:120`); the onboarding prompt that surfaces OpenRouter as the worked example is in `handleRemoteProviderSelection` in `src/lib/onboard.ts`. Behavior on other OpenAI-compatible proxies, gateways, and self-hosted implementations may vary; this row claims the adapter, not the universe of compatible endpoints. |
| Anthropic | Tested | Native Anthropic | Uses anthropic-messages |
| Other Anthropic-compatible endpoint | Tested with limitations | Custom Anthropic-compatible | Adapter path validated with AWS Bedrock (`src/lib/onboard/bedrock-runtime.ts`). Behavior on other Anthropic-compatible proxies and gateways may vary; this row claims the adapter, not the universe of compatible endpoints. |
| Google Gemini | Tested | OpenAI-compatible | Uses Google's OpenAI-compatible endpoint |
Expand Down
55 changes: 55 additions & 0 deletions src/lib/inference/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { describe, expect, it } from "vitest";
// Import source directly so tests cannot pass against a stale build.
import {
CLOUD_MODEL_OPTIONS,
coerceAgentInferenceApi,
DEFAULT_CLOUD_MODEL,
DEFAULT_HERMES_PROVIDER_MODEL,
DEFAULT_OLLAMA_MODEL,
Expand Down Expand Up @@ -338,6 +339,25 @@ describe("getSandboxInferenceConfig", () => {
});
});

it("keeps the /v1 suffix for an OpenAI-only agent coerced off the Anthropic Messages route (#6294)", () => {
const openaiOnlyAgent = { inference: { provider_type: "openai_compatible" } };
expect(
getSandboxInferenceConfig(
"claude-sonnet-proxy",
"compatible-anthropic-endpoint",
coerceAgentInferenceApi(openaiOnlyAgent, "anthropic-messages"),
),
).toEqual({
providerKey: MANAGED_PROVIDER_ID,
primaryModelRef: `${MANAGED_PROVIDER_ID}/claude-sonnet-proxy`,
inferenceBaseUrl: INFERENCE_ROUTE_URL,
inferenceApi: "openai-completions",
inferenceCompat: {
supportsStore: false,
},
});
});

it("maps Gemini to the routed inference provider with supportsStore disabled", () => {
expect(getSandboxInferenceConfig("gemini-2.5-flash", "gemini-api")).toEqual({
providerKey: MANAGED_PROVIDER_ID,
Expand All @@ -361,6 +381,41 @@ describe("getSandboxInferenceConfig", () => {
});
});

describe("coerceAgentInferenceApi", () => {
const openaiOnlyAgent = { inference: { provider_type: "openai_compatible" } };

it("routes an OpenAI-only agent off Anthropic Messages onto openai-completions (#6294)", () => {
expect(coerceAgentInferenceApi(openaiOnlyAgent, "anthropic-messages")).toBe(
"openai-completions",
);
});

it("leaves an OpenAI-only agent already on openai-completions unchanged", () => {
expect(coerceAgentInferenceApi(openaiOnlyAgent, "openai-completions")).toBe(
"openai-completions",
);
});

it("leaves an unresolved (null) inference API untouched so the caller defaults it", () => {
expect(coerceAgentInferenceApi(openaiOnlyAgent, null)).toBeNull();
});

it("does not touch gateway-managed agents (OpenClaw) that speak Anthropic natively", () => {
const openclawAgent = { inference: { provider_type: "gateway_managed" } };
expect(coerceAgentInferenceApi(openclawAgent, "anthropic-messages")).toBe("anthropic-messages");
});

it("does not touch custom-provider agents (Hermes) that speak Anthropic natively", () => {
const hermesAgent = { inference: { provider_type: "custom" } };
expect(coerceAgentInferenceApi(hermesAgent, "anthropic-messages")).toBe("anthropic-messages");
});

it("is a no-op when the agent or its inference block is absent", () => {
expect(coerceAgentInferenceApi(null, "anthropic-messages")).toBe("anthropic-messages");
expect(coerceAgentInferenceApi({}, "anthropic-messages")).toBe("anthropic-messages");
});
});

describe("parseGatewayInference", () => {
it("parses provider and model from openshell inference get output", () => {
const output = [
Expand Down
31 changes: 31 additions & 0 deletions src/lib/inference/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,37 @@ export function getSandboxInferenceConfig(
return { providerKey, primaryModelRef, inferenceBaseUrl, inferenceApi, inferenceCompat };
}

/**
* OpenAI `/chat/completions`-only agents (manifest `provider_type:
* openai_compatible`, e.g. `langchain-deepagents-code` / dcode) cannot speak
* the Anthropic Messages API. When such an agent is onboarded against an
* Anthropic-compatible endpoint, the endpoint probe resolves the inference API
* to `anthropic-messages`, which routes getSandboxInferenceConfig() through the
* raw Anthropic branch — dropping the `/v1` suffix the OpenAI client appends to
* `/chat/completions` and wiring the sandbox for the wrong contract. The
* OpenShell sandbox L7 inference proxy only recognizes fixed `/v1` API paths,
* so the `/chat/completions` call (no `/v1`) is denied with a 403, surfaced as
* PermissionDeniedError. Route such agents through the managed
* OpenAI-compatible config instead — the same getSandboxInferenceConfig branch
* the Bedrock Runtime custom-Anthropic flow uses — so the baked base_url keeps
* its `/v1` suffix. Note this fixes the sandbox-side wiring only: the gateway
* provider for compatible-anthropic-endpoint is still registered as
* type=anthropic, whose route accepts only the anthropic_messages protocol, so
* openai_chat_completions traffic needs a gateway-side answer (translation,
* type switch, or onboarding rejection) tracked on #6294.
*/
export function coerceAgentInferenceApi(
agent: unknown,
preferredInferenceApi: string | null,
): string | null {
const providerType = (agent as { inference?: { provider_type?: string } } | null | undefined)
?.inference?.provider_type;
if (providerType === "openai_compatible" && preferredInferenceApi === "anthropic-messages") {
return "openai-completions";
}
return preferredInferenceApi;
}

export function parseGatewayInference(output: string | null | undefined): GatewayInference | null {
if (!output) return null;
const stripped = output.replace(/\u001b\[[0-9;]*m/g, "");
Expand Down
2 changes: 1 addition & 1 deletion src/lib/onboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4145,7 +4145,7 @@ async function setupNim(gpu: ReturnType<typeof nim.detectGpu>, sandboxName: stri
credentialEnv,
hermesAuthMethod,
hermesToolGateways,
preferredInferenceApi,
preferredInferenceApi: inferenceConfig.coerceAgentInferenceApi(agent, preferredInferenceApi),
compatibleEndpointReasoning,
nimContainer,
allowToolsIncompatible,
Expand Down
141 changes: 131 additions & 10 deletions src/lib/onboard/inference-providers/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,19 @@
// onboard.setupInference (#767). Bedrock Runtime is delegated to
// `onboard/bedrock-runtime.ts` exactly as the inline branch did.

import { readGatewayProviderMetadata } from "../gateway-provider-metadata";
import { deleteProviderWithRecovery, parseAttachedSandboxes } from "../sandbox-provider-cleanup";
import type { RemoteProviderDeps, SetupInferenceResult } from "./types";

const { probeOpenAiLikeEndpoint } = require("../../inference/onboard-probes") as {
probeOpenAiLikeEndpoint: (
endpointUrl: string,
model: string,
apiKey: string,
options?: Record<string, unknown>,
) => { ok: boolean; message?: string };
};

/**
* Returns `{ done: true, result }` when the flow handled the request
* (e.g. Bedrock short-circuit or a retry-to-selection); returns
Expand All @@ -22,6 +33,7 @@ export async function setupRemoteProviderInference(
endpointUrl: string | null;
credentialEnv: string | null;
reuseGatewayCredentialWithoutLocalKey?: boolean;
preferredInferenceApi?: string | null;
},
deps: RemoteProviderDeps,
): Promise<{ done: true; result: SetupInferenceResult } | { done: false }> {
Expand All @@ -32,6 +44,7 @@ export async function setupRemoteProviderInference(
endpointUrl,
credentialEnv,
reuseGatewayCredentialWithoutLocalKey,
preferredInferenceApi,
} = args;
const {
runOpenshell,
Expand Down Expand Up @@ -78,6 +91,28 @@ export async function setupRemoteProviderInference(
log,
});
if (bedrockSetup.handled) return { done: true, result: bedrockSetup.result };
// #6294: an OpenAI-/chat/completions-only agent (dcode) coerced off Anthropic
// Messages must talk to the gateway route over the openai_chat_completions
// protocol, and OpenShell routes that protocol only for providers registered
// with type=openai. Verify the endpoint actually serves the OpenAI surface
// before registering it as such; endpoints that answer only /v1/messages get
// an actionable onboarding failure instead of a sandbox that cannot infer.
// Bedrock endpoints never reach here — the adapter branch above returns first.
const useOpenAiSurface =
provider === "compatible-anthropic-endpoint" && preferredInferenceApi === "openai-completions";
const probeOpenAiSurface = deps.probeOpenAiLikeEndpoint ?? probeOpenAiLikeEndpoint;
// The concrete modules type their openshell runners independently; the deps
// runner is call-compatible with both, so bridge the nominal mismatch here.
const readProviderMetadata =
deps.readGatewayProviderMetadata ??
(readGatewayProviderMetadata as unknown as NonNullable<
RemoteProviderDeps["readGatewayProviderMetadata"]
>);
const removeGatewayProvider =
deps.deleteGatewayProvider ??
(deleteProviderWithRecovery as unknown as NonNullable<
RemoteProviderDeps["deleteGatewayProvider"]
>);
while (true) {
const resolvedCredentialEnv = credentialEnv || (config && config.credentialEnv);
const resolvedEndpointUrl = endpointUrl || (config && config.endpointUrl);
Expand All @@ -104,19 +139,105 @@ export async function setupRemoteProviderInference(
resolvedCredentialEnv && credentialValue
? { [resolvedCredentialEnv]: credentialValue }
: {};
providerResult = credentialValue
? upsertProvider(
provider,
config.providerType,
resolvedCredentialEnv,
resolvedEndpointUrl,
env,
)
: {
if (!credentialValue) {
providerResult = {
ok: false,
status: 1,
message: `A host credential is required to configure provider '${provider}'.`,
};
} else if (useOpenAiSurface) {
// The anthropic-flavor endpoint normalization strips a trailing /v1
// (core/url-utils), while OpenShell resolves openai_chat_completions
// to <OPENAI_BASE_URL>/v1/chat/completions, deduping only bases that
// already end in /v1. Re-add the suffix so the probe and the runtime
// route exercise the identical URL.
const trimmedSurfaceBase = String(resolvedEndpointUrl ?? "").replace(/\/+$/, "");
const openAiSurfaceBaseUrl = trimmedSurfaceBase.endsWith("/v1")
? trimmedSurfaceBase
: `${trimmedSurfaceBase}/v1`;
const surfaceProbe = probeOpenAiSurface(openAiSurfaceBaseUrl, model, credentialValue, {
skipResponsesProbe: true,
});
if (!surfaceProbe.ok) {
providerResult = {
ok: false,
status: 1,
message: `A host credential is required to configure provider '${provider}'.`,
message: compactText(
redact(
`The selected agent requires an OpenAI-compatible /v1/chat/completions surface, ` +
`but the endpoint did not answer it${surfaceProbe.message ? `: ${surfaceProbe.message}` : "."} ` +
`Use an endpoint that also serves /v1/chat/completions, or onboard an agent that ` +
`supports the Anthropic Messages API (e.g. openclaw or hermes).`,
),
),
};
} else {
// `provider update` cannot change --type, so a provider left behind
// by an earlier Anthropic-Messages registration must be replaced.
// Containment: force-detach recovery may only touch the sandbox
// being onboarded — flipping a provider that other live sandboxes
// are attached to would silently break their Anthropic routing, so
// that case fails closed with an actionable message instead.
const live = readProviderMetadata(provider, runOpenshell);
let replaced: { ok: boolean; status?: number | null; message?: string } = { ok: true };
if (live && live.type !== "openai") {
const attempt = runOpenshell(["provider", "delete", provider], {
ignoreError: true,
suppressOutput: true,
});
if (attempt.status !== 0) {
const raw = `${attempt.stderr || ""}\n${attempt.stdout || ""}`;
const attached = parseAttachedSandboxes(raw);
const foreign = attached.filter((name) => name !== sandboxName);
if (attached.length > 0 && foreign.length === 0) {
const recovery = removeGatewayProvider(provider, { runOpenshell });
replaced = recovery.ok
? { ok: true }
: {
ok: false,
status: recovery.status ?? 1,
message:
`Failed to replace provider '${provider}' for the OpenAI-compatible route` +
`${compactText(redact(`${recovery.stderr || ""} ${recovery.stdout || ""}`)) ? `: ${compactText(redact(`${recovery.stderr || ""} ${recovery.stdout || ""}`))}` : "."}`,
};
} else if (foreign.length > 0) {
replaced = {
ok: false,
status: attempt.status ?? 1,
message:
`Provider '${provider}' is attached to other sandbox(es) (${foreign.join(", ")}) ` +
`and cannot be re-registered for the OpenAI-compatible route without breaking ` +
`their Anthropic Messages routing. Onboard this agent against a dedicated ` +
`endpoint or remove those sandboxes first.`,
};
} else {
replaced = {
ok: false,
status: attempt.status ?? 1,
message:
`Failed to replace provider '${provider}' for the OpenAI-compatible route` +
`${compactText(redact(raw)) ? `: ${compactText(redact(raw))}` : "."}`,
};
}
}
}
providerResult = replaced.ok
? upsertProvider(provider, "openai", resolvedCredentialEnv, openAiSurfaceBaseUrl, env)
: {
ok: false,
status: replaced.status || 1,
message: replaced.message ?? `Failed to replace provider '${provider}'.`,
};
}
} else {
providerResult = upsertProvider(
provider,
config.providerType,
resolvedCredentialEnv,
resolvedEndpointUrl,
env,
);
}
}
if (!providerResult.ok) {
error(` ${providerResult.message}`);
Expand Down
17 changes: 17 additions & 0 deletions src/lib/onboard/inference-providers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,23 @@ export type RemoteProviderDeps = CommonDeps & {
LOCAL_INFERENCE_TIMEOUT_SECS: number;
redact: (input: string) => string;
compactText: (input: string) => string;
// #6294 OpenAI-surface registration for openai_compatible agents onboarded
// on compatible-anthropic-endpoint. Optional: production falls back to the
// real implementations inside remote.ts; tests inject fakes.
probeOpenAiLikeEndpoint?: (
endpointUrl: string,
model: string,
apiKey: string,
options?: Record<string, unknown>,
) => { ok: boolean; message?: string };
readGatewayProviderMetadata?: (
name: string,
runOpenshell: RunOpenshell,
) => { name: string; type: string; credentialKeys: string[]; configKeys: string[] } | null;
deleteGatewayProvider?: (
name: string,
deps: { runOpenshell: RunOpenshell },
) => { ok: boolean; status?: number | null; stderr?: string; stdout?: string };
bedrockRuntimeOnboard: {
setupBedrockRuntimeInference(input: {
sandboxName: string | null;
Expand Down
Loading
Loading