Skip to content

feat(provider): add Morph as a gateway provider for large open-source models#4245

Open
shreybirmiwalmorph wants to merge 10 commits into
Kilo-Org:mainfrom
shreybirmiwalmorph:feat/morph-gateway-provider
Open

feat(provider): add Morph as a gateway provider for large open-source models#4245
shreybirmiwalmorph wants to merge 10 commits into
Kilo-Org:mainfrom
shreybirmiwalmorph:feat/morph-gateway-provider

Conversation

@shreybirmiwalmorph

@shreybirmiwalmorph shreybirmiwalmorph commented Jun 25, 2026

Copy link
Copy Markdown

Adds morph as gateway provider.

Kilo will need to set MORPH_API_KEY

Models added

public_id internal gateway id context
morph/qwen3.5-397b morph-qwen35-397b 262K
morph/qwen3.6-27b morph-qwen36-27b 131K
morph/minimax-m2.7 morph-minimax27-230b 196K
morph/minimax-m3 morph-minimax3-428b 256K
morph/glm-5.2 morph-glm52-744b 450K
morph/deepseek-v4-flash morph-dsv4flash 1M

};

export const morph_minimax_m27_model: KiloExclusiveModel = {
public_id: 'morph/minimax-m2.7',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: Morph MiniMax models will fail for OpenCode clients

getGatewayOpenCodeSettings() treats any *minimax* model as ai_sdk_provider: 'anthropic', and CustomLlmProviderSchema documents that as the Messages API. Because MORPH.supportedChatApis only exposes chat_completions, requests for both morph/minimax-m2.7 and morph/minimax-m3 are rejected by apiKindNotSupportedResponse before they ever reach Morph. Either override these ids to an OpenAI-compatible provider or add /messages support for the Morph gateway.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — fixed in 40795bd.

getAiSdkProvider mapped any *minimax* id to the Anthropic Messages API, which the Morph gateway (chat_completions only) rejects via apiKindNotSupportedResponse. Rather than patch just the two MiniMax ids, I pinned every Morph model to openai-compatible at the top of getAiSdkProvider, encoding the gateway invariant and guarding the whole class (also protects future gpt/grok-named ids from being routed to the Responses API). Added regression coverage asserting all six Morph models resolve to a chat_completions-compatible OpenCode provider.

Also verified live against api.morphllm.com: all six models return 200 with correct output + usage, and the two vision-flagged models (qwen3.5-397b, minimax-m3) correctly process image input.

@kilo-code-bot

kilo-code-bot Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (1 files)
  • apps/web/src/lib/ai-gateway/providers/morph.test.ts
Previous Review Summaries (9 snapshots, latest commit 29ffb5c)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 29ffb5c)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (1 files)
  • apps/web/src/lib/ai-gateway/providers/morph.test.ts

Previous review (commit 4ee98f1)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (2 files)
  • apps/web/src/lib/ai-gateway/providers/morph.test.ts
  • apps/web/src/lib/ai-gateway/providers/morph.ts

Previous review (commit 6f9ce6c)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (1 files)
  • apps/web/src/lib/ai-gateway/providers/morph.test.ts

Previous review (commit 40795bd)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (2 files)
  • apps/web/src/lib/ai-gateway/providers/model-settings.ts
  • apps/web/src/lib/ai-gateway/providers/morph.test.ts

Previous review (commit aada3de)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (2 files)
  • apps/web/src/lib/ai-gateway/providers/morph.test.ts
  • apps/web/src/lib/ai-gateway/providers/morph.ts

Previous review (commit f632630)

Status: 1 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
apps/web/src/lib/ai-gateway/providers/morph.ts 63 Morph MiniMax models still advertise the Anthropic/Messages path to OpenCode even though the Morph gateway only supports Chat Completions.
Files Reviewed (1 files)
  • apps/web/src/lib/ai-gateway/providers/morph.ts - 1 issue

Fix these issues in Kilo Cloud

Previous review (commit aff4c19)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (2 files)
  • apps/web/src/lib/ai-gateway/providers/morph.test.ts
  • apps/web/src/lib/ai-gateway/providers/morph.ts

Previous review (commit f942d39)

Status: 1 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
apps/web/src/lib/ai-gateway/providers/morph.ts 63 Morph MiniMax models still advertise the Anthropic/Messages path to OpenCode even though the Morph gateway only supports Chat Completions.
Files Reviewed (4 files)
  • apps/web/src/lib/ai-gateway/models.ts
  • apps/web/src/lib/ai-gateway/providers/morph.ts - 1 issue
  • apps/web/src/lib/ai-gateway/providers/provider-definitions.ts
  • apps/web/src/lib/ai-gateway/providers/types.ts

Fix these issues in Kilo Cloud

Previous review (commit deb5357)

Status: 1 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
apps/web/src/lib/ai-gateway/providers/morph.ts 63 Morph MiniMax models are advertised through the Messages API even though the Morph provider only supports Chat Completions.
Files Reviewed (4 files)
  • apps/web/src/lib/ai-gateway/models.ts
  • apps/web/src/lib/ai-gateway/providers/morph.ts - 1 issue
  • apps/web/src/lib/ai-gateway/providers/provider-definitions.ts
  • apps/web/src/lib/ai-gateway/providers/types.ts

Fix these issues in Kilo Cloud


Reviewed by gpt-5.4-20260305 · Input: 71.4K · Output: 4.3K · Cached: 237.6K

Review guidance: REVIEW.md from base branch main

… models

Adds Morph (https://api.morphllm.com/v1, OpenAI-compatible) as a first-party
gateway provider and registers the large open-source models Morph serves on its
own fleet: Qwen3.5 397B, Qwen3.6 27B, MiniMax M2.7, MiniMax M3, GLM-5.2, and
DeepSeek V4 Flash. Excludes Morph's proprietary models (apply/v3, compactor,
warp-grep, embeddings).

Routing reuses the existing gateway->provider resolution in get-provider.ts;
'morph' is already a recognized inference-provider id. Kilo holds the key via
MORPH_API_KEY. Pricing and context windows mirror Morph's published numbers.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@shreybirmiwalmorph shreybirmiwalmorph force-pushed the feat/morph-gateway-provider branch from deb5357 to f942d39 Compare June 25, 2026 02:35
shreybirmiwalmorph and others added 9 commits June 24, 2026 20:23
Reconcile Morph gateway pricing against the canonical source
(https://www.morphllm.com/api/models/json + landing/src/lib/pricing.ts
cost functions):

- GLM-5.2: set input_cache_read to $0.35/1M. Morph's calculateChatGlm52Cost
  bills cached input at this rate (LMCache prefix reuse); the models JSON
  currently omits the field, so the prior null under-priced cache reads.
- Verified the other five models: qwen3.5 keeps its $0.30 cache rate; the
  rest (qwen3.6, minimax m2.7/m3, deepseek-v4-flash) have no cache-read
  billing in Morph's cost functions, so they correctly stay null. The
  minimax cache rates present in MODEL_PRICING config are never applied by
  the cost functions, so they are intentionally not exposed here.

Adds morph.test.ts covering: Morph provider config, the six registered
open-source models (and exclusion of proprietary apply/compactor/etc.),
gateway->provider resolution to PROVIDERS.MORPH (the same lookup
get-provider.ts uses), and per-model pricing.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Match Morph's canonical context (MODEL_CONTEXT_WINDOWS / api/models/json):
GLM-5.2 serves a 1,048,576-token window, not 450k.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…l source

Reconcile all six Morph gateway models against the canonical source of truth
(https://www.morphllm.com/api/models/json). Per-1M prompt/completion/cache-read
rates and context windows already match exactly; no pricing change needed.

The canonical JSON marks qwen3.5-397b and minimax-m3 as image-capable
(input_modalities: ["text","image"]), so add the 'vision' flag to those two and
assert vision support (and reasoning) for every model in the test matrix.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ents

getAiSdkProvider maps any '*minimax*' id to the Anthropic Messages API (and
gpt/grok ids to the OpenAI Responses API). Morph's gateway only exposes
chat_completions (MORPH.supportedChatApis), so OpenCode requests for
morph/minimax-m2.7 and morph/minimax-m3 were rejected by
apiKindNotSupportedResponse before reaching Morph.

Pin every Morph model to the 'openai-compatible' AI SDK provider at the top of
getAiSdkProvider, encoding the gateway's real invariant and guarding the whole
bug class (not just minimax). Add regression coverage asserting all six Morph
models resolve to a chat_completions-compatible OpenCode provider.

Reported-by: kilo-code-bot on PR Kilo-Org#4245.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…t_mUsd

Add cost-calculation coverage proving the stored per-million rates produce the
right micro-USD bills, not just that the numbers are present:
- qwen3.5/glm-5.2 cache reads bill at the discounted cache_read rate (< prompt)
- models without a cache_read price (e.g. deepseek-v4-flash) fall back to the
  prompt rate for cache hits (not free)
- a mixed uncached + cache-hit + output bill matches the expected total

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…/json)

The canonical models JSON advertises a cache rate only for qwen3.5 (0.3);
GLM-5.2 has none. Set input_cache_read_per_million to null and update the
test so GLM-5.2 bills cache hits at the prompt rate, like the other
non-cache models.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Drop the Morph provider unit test (all assertions passed; removing per request
to keep the PR to the provider addition itself).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add back the deterministic unit test (26 cases): provider config, the 6
registered models, gateway->PROVIDERS.MORPH routing, pricing vs canonical
(GLM no-cache, qwen3.5 0.3), vision flags, and cache billing. No network/key
needed — safe for CI.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@bhaktatejas922

Copy link
Copy Markdown

@shreybirmiwalmorph this stuff should pull from the live endpoint https://www.morphllm.com/api/models/json

@bhaktatejas922

Copy link
Copy Markdown

@arimesser

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants