Skip to content

armgit / Orkas

Public Imported from GitHub
0

Orkas is an open-source (MIT), local-first AI team for your desktop: a Commander turns your goal into to-dos and coordinates 16 built-in specialist agents plus Claude Code, Codex, OpenCode, OpenClaw and Hermes, with projects, scheduled automations and connectors. Free app for macOS & Windows; built-in models or your own keys.

feat: support custom Anthropic model protocol

Test Usere7fbf84d2a0a
diff --git a/src/main/features/auth.ts b/src/main/features/auth.ts
index c232d4fb..8ec809f0 100644
--- a/src/main/features/auth.ts
+++ b/src/main/features/auth.ts
@@ -187,8 +187,9 @@ interface ApiKeyProfile {
provider: string;
label: string;
key: string;
- /** Present only for the `custom` OpenAI-compatible provider. */
+ /** Present only for the custom provider. */
baseUrl?: string;
+ protocol?: 'openai' | 'anthropic';
contextWindow?: number;
maxTokens?: number;
supportsReasoning?: boolean;
@@ -1050,6 +1051,7 @@ function customRuntimeConfigFromProfile(
if (!profile || profile.type !== 'api_key' || profile.provider !== CUSTOM_MODEL_PROVIDER) return null;
try {
const baseUrl = normalizeCustomModelBaseUrl(profile.baseUrl || '');
+ const protocol = profile.protocol === 'anthropic' ? 'anthropic' : 'openai';
const contextWindow = normalizeCustomTokenLimit(
profile.contextWindow,
DEFAULT_CUSTOM_CONTEXT_WINDOW,
@@ -1065,6 +1067,7 @@ function customRuntimeConfigFromProfile(
? profile.reasoningEffort as 'low' | 'medium' | 'high'
: undefined;
return {
+ protocol,
baseUrl,
contextWindow,
maxTokens,
@@ -1432,6 +1435,7 @@ export async function addApiKeyEntry(
export interface AddCustomModelEntryInput {
label?: string;
+ protocol?: 'openai' | 'anthropic' | string;
baseUrl: string;
model: string;
apiKey: string;
@@ -1448,6 +1452,7 @@ export async function addCustomModelEntry(
): Promise<{ profileId: string; entryId: string }> {
const rawLabel = String(input?.label || '').trim();
const model = String(input?.model || '').trim();
+ const protocol = input?.protocol === 'anthropic' ? 'anthropic' : 'openai';
const key = String(input?.apiKey || '').trim();
if (!model) throw customConfigError('CUSTOM_MODEL_REQUIRED', 'Model ID required');
if (!key) throw customConfigError('CUSTOM_API_KEY_REQUIRED', 'API key required');
@@ -1508,6 +1513,7 @@ export async function addCustomModelEntry(
label: chosenLabel,
key,
baseUrl,
+ protocol,
contextWindow,
...(maxTokens !== undefined ? { maxTokens } : {}),
...(input.supportsReasoning === true ? { supportsReasoning: true } : {}),
diff --git a/src/main/model/core-agent/external-providers.ts b/src/main/model/core-agent/external-providers.ts
index 1b52b924..7cccff98 100644
--- a/src/main/model/core-agent/external-providers.ts
+++ b/src/main/model/core-agent/external-providers.ts
@@ -591,6 +591,31 @@ export function buildCustomOpenAICompatibleModel(
};
}
+export function buildCustomAnthropicModel(
+ modelId: string,
+ config: CustomOpenAICompatibleRuntimeConfig,
+): Model<'anthropic-messages'> {
+ return {
+ id: modelId,
+ name: modelId,
+ api: 'anthropic-messages',
+ provider: 'custom' as any,
+ baseUrl: config.baseUrl,
+ reasoning: config.supportsReasoning === true,
+ input: config.supportsVision === false ? ['text'] : ['text', 'image'],
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
+ contextWindow: config.contextWindow,
+ maxTokens: config.maxTokens,
+ compat: {
+ supportsDeveloperRole: false,
+ supportsStore: false,
+ supportsReasoningEffort: false,
+ supportsStrictMode: false,
+ supportsLongCacheRetention: false,
+ },
+ };
+}
+
export async function createCustomOpenAICompatibleProvider(
config: CreateCustomOpenAICompatibleProviderConfig,
): Promise<LLMProvider> {
@@ -607,12 +632,17 @@ export async function createCustomOpenAICompatibleProvider(
if (!config.baseUrl) throw new Error('custom: baseUrl required');
const mod = await ca();
const compatibility = createCustomOutputLimitCompatibility(config);
+ const isAnthropic = config.protocol === 'anthropic';
return mod.createPiProvider({
provider: 'custom',
apiKey: config.apiKey,
- customModel: buildCustomOpenAICompatibleModel(config.modelId, config),
+ customModel: isAnthropic
+ ? buildCustomAnthropicModel(config.modelId, config)
+ : buildCustomOpenAICompatibleModel(config.modelId, config),
normalizeLiteralLeadingThinkText: true,
- onPayload: payload => compatibility.onPayload(repairOpenAICompatiblePayload(payload)),
+ onPayload: payload => isAnthropic
+ ? compatibility.onPayload(payload)
+ : compatibility.onPayload(repairOpenAICompatiblePayload(payload)),
wrapFetch: compatibility.wrapFetch,
...(config.reasoningEffort ? { defaultReasoning: config.reasoningEffort } : {}),
});
diff --git a/src/main/model/core-agent/runner.ts b/src/main/model/core-agent/runner.ts
index e54b8160..c0c68b0b 100644
--- a/src/main/model/core-agent/runner.ts
+++ b/src/main/model/core-agent/runner.ts
@@ -115,6 +115,7 @@ import {
createDeepSeekProvider,
createDoubaoProvider,
buildCustomOpenAICompatibleModel,
+ buildCustomAnthropicModel,
createCustomOpenAICompatibleProvider,
omitReservedOutputLimitForProvider,
} from './external-providers';
@@ -176,7 +177,11 @@ function buildExternalProviderModel(
case 'doubao':
return buildDoubaoModel(modelId);
case 'custom':
- return customConfig ? buildCustomOpenAICompatibleModel(modelId, customConfig) : null;
+ return customConfig
+ ? (customConfig.protocol === 'anthropic'
+ ? buildCustomAnthropicModel(modelId, customConfig)
+ : buildCustomOpenAICompatibleModel(modelId, customConfig))
+ : null;
default:
return null;
}
diff --git a/src/main/model/provider_catalog.ts b/src/main/model/provider_catalog.ts
index 81fb1f3b..d5e0aee8 100644
--- a/src/main/model/provider_catalog.ts
+++ b/src/main/model/provider_catalog.ts
@@ -707,6 +707,8 @@ export function providerUsesCustomOpenAIConfig(id: string): boolean {
}
export interface CustomOpenAICompatibleRuntimeConfig {
+ /** Wire protocol; omitted legacy configs use OpenAI-compatible chat completions. */
+ protocol?: 'openai' | 'anthropic';
baseUrl: string;
contextWindow: number;
maxTokens: number;
diff --git a/src/renderer/locales/en.json b/src/renderer/locales/en.json
index 572a6878..12109a45 100644
--- a/src/renderer/locales/en.json
+++ b/src/renderer/locales/en.json
@@ -1772,7 +1772,8 @@
"settings.modal.label_placeholder": "Optional, e.g. Default, Work, Personal",
"settings.modal.docs_prefix": "Create at {url}",
"settings.custom.title": "Add custom model",
- "settings.custom.compat_hint": "For OpenAI-compatible Chat Completions APIs.",
+ "settings.custom.compat_hint": "Choose the protocol supported by your gateway.",
+ "settings.custom.protocol": "Protocol",
"settings.custom.label": "Label (optional)",
"settings.custom.label_placeholder": "For example: company gateway",
"settings.custom.base_url": "API Base URL",
diff --git a/src/renderer/locales/zh.json b/src/renderer/locales/zh.json
index 66191f9c..4606eae0 100644
--- a/src/renderer/locales/zh.json
+++ b/src/renderer/locales/zh.json
@@ -1772,7 +1772,8 @@
"settings.modal.label_placeholder": "可选,例如:默认、工作、个人",
"settings.modal.docs_prefix": "从 {url} 创建",
"settings.custom.title": "添加自定义模型",
- "settings.custom.compat_hint": "适用于 OpenAI 兼容的 Chat Completions 接口。",
+ "settings.custom.compat_hint": "请选择中转支持的协议。",
+ "settings.custom.protocol": "协议",
"settings.custom.label": "标签(可选)",
"settings.custom.label_placeholder": "例如:公司网关",
"settings.custom.base_url": "API Base URL",
diff --git a/src/renderer/modules/settings.js b/src/renderer/modules/settings.js
index 7a3da6a9..d258585c 100644
--- a/src/renderer/modules/settings.js
+++ b/src/renderer/modules/settings.js
@@ -1578,6 +1578,7 @@ function _settingsBuildCustomModelPayload(values) {
const maxTokens = String(values.maxTokens ?? '').trim();
return {
label: String(values.label || '').trim(),
+ protocol: values.protocol === 'anthropic' ? 'anthropic' : 'openai',
baseUrl: _settingsNormalizeCustomBaseUrl(values.baseUrl),
model: String(values.model || '').trim(),
apiKey: String(values.apiKey || '').trim(),
@@ -1604,6 +1605,13 @@ function _settingsShowCustomModelForm(provider) {
<label>${escapeHtml(t('settings.custom.label'))}</label>
<input type="text" class="custom-label-input form-input" placeholder="${escapeHtml(t('settings.custom.label_placeholder'))}" autocomplete="off" spellcheck="false" />
</div>
+ <div class="form-row">
+ <label>${escapeHtml(t('settings.custom.protocol'))}</label>
+ <select class="custom-protocol-input form-input">
+ <option value="openai">OpenAI-compatible</option>
+ <option value="anthropic">Anthropic Messages</option>
+ </select>
+ </div>
<div class="form-row">
<label>${escapeHtml(t('settings.custom.base_url'))}</label>
<input type="text" class="custom-base-url-input form-input" placeholder="https://api.example.com/v1" autocomplete="off" spellcheck="false" />
@@ -1626,6 +1634,7 @@ function _settingsShowCustomModelForm(provider) {
actions.innerHTML = '';
const labelInput = body.querySelector('.custom-label-input');
+ const protocolInput = body.querySelector('.custom-protocol-input');
const baseUrlInput = body.querySelector('.custom-base-url-input');
const modelInput = body.querySelector('.custom-model-input');
const maxTokensInput = body.querySelector('.custom-max-tokens-input');
@@ -1644,6 +1653,7 @@ function _settingsShowCustomModelForm(provider) {
const startedAt = Date.now();
const payload = _settingsBuildCustomModelPayload({
label: labelInput.value,
+ protocol: protocolInput.value,
baseUrl: baseUrlInput.value,
model: modelInput.value,
maxTokens: maxTokensInput.value,
@@ -1692,7 +1702,8 @@ function _settingsShowCustomModelForm(provider) {
if (e.key === 'Enter') { next.focus(); e.preventDefault(); }
});
};
- focusNextOnEnter(labelInput, baseUrlInput);
+ focusNextOnEnter(labelInput, protocolInput);
+ focusNextOnEnter(protocolInput, baseUrlInput);
focusNextOnEnter(baseUrlInput, modelInput);
focusNextOnEnter(modelInput, maxTokensInput);
focusNextOnEnter(maxTokensInput, keyInput);
diff --git a/test/main/features/auth.test.ts b/test/main/features/auth.test.ts
index db2986f7..d82ee404 100644
--- a/test/main/features/auth.test.ts
+++ b/test/main/features/auth.test.ts
@@ -416,6 +416,24 @@ describe('auth › listProviders grouping', () => {
});
describe('auth › custom OpenAI-compatible model configuration', () => {
+ it('persists Anthropic protocol and returns it in the runtime choice', async () => {
+ const a = await import('../../../src/main/features/auth');
+ const added = await a.addCustomModelEntry({
+ protocol: 'anthropic',
+ baseUrl: 'https://gateway.example.test',
+ model: 'claude-3-7-sonnet',
+ apiKey: 'sk-custom-anthropic-xxxxxxxx',
+ });
+ expect((await a.pickChatEntryGroup()).find((entry) => entry.entryId === added.entryId)).toEqual(
+ expect.objectContaining({
+ customConfig: expect.objectContaining({
+ protocol: 'anthropic',
+ baseUrl: 'https://gateway.example.test',
+ }),
+ }),
+ );
+ });
+
it('atomically stores endpoint metadata and carries it into the runtime choice', async () => {
const a = await import('../../../src/main/features/auth');
const added = await a.addCustomModelEntry({
diff --git a/test/main/model/core-agent/external-providers.test.ts b/test/main/model/core-agent/external-providers.test.ts
index e4e074c3..003acd4e 100644
--- a/test/main/model/core-agent/external-providers.test.ts
+++ b/test/main/model/core-agent/external-providers.test.ts
@@ -1,6 +1,7 @@
import { describe, it, expect } from 'vitest';
import {
buildCustomOpenAICompatibleModel,
+ buildCustomAnthropicModel,
buildDeepSeekModel,
buildDoubaoModel,
buildMoonshotModel,
@@ -60,6 +61,22 @@ describe('external-providers › custom OpenAI-compatible model', () => {
});
});
+describe('external-providers › custom Anthropic model', () => {
+ it('uses the native Anthropic Messages API and preserves custom limits', () => {
+ expect(buildCustomAnthropicModel('claude-3-7-sonnet', {
+ baseUrl: 'https://gateway.example.test',
+ contextWindow: 200_000,
+ maxTokens: 8_192,
+ })).toMatchObject({
+ api: 'anthropic-messages',
+ baseUrl: 'https://gateway.example.test',
+ input: ['text', 'image'],
+ contextWindow: 200_000,
+ maxTokens: 8_192,
+ });
+ });
+});
+
describe('external-providers › Orkas API model', () => {
it('uses the public chat endpoint and preserves the selected public model id', () => {
expect(buildOrkasApiModel('orkas-llm-1.5-pro')).toMatchObject({