Skip to content

feat(providers): native DeepSeek V4 Flash adapter via official API - #282

Open
qpdv (qpd-v) wants to merge 1 commit into
synthetic-sciences:mainfrom
qpd-v:feat/deepseek-native-adapter
Open

feat(providers): native DeepSeek V4 Flash adapter via official API#282
qpdv (qpd-v) wants to merge 1 commit into
synthetic-sciences:mainfrom
qpd-v:feat/deepseek-native-adapter

Conversation

@qpd-v

Copy link
Copy Markdown

Summary

Adds a native DeepSeek adapter via the official API (https://api.deepseek.com), so deepseek-v4-* models work end-to-end without being routed through the generic OpenAI-compatible adapter (which mishandles V4's reasoning and strict tool-schema validation).

What changed

  • Native adapter resolution. The deepseek provider now resolves to @ai-sdk/deepseek in both npm-resolution chains (models.dev ingestion + config-provider merge). The V2-spec adapter replays reasoning_content across tool loops and exposes thinking / reasoningEffort / strictJsonSchema.
  • Official-endpoint loader. Added a deepseek custom loader that pins https://api.deepseek.com, honors DEEPSEEK_BASE_URL, and resolves the key from openscience keys add deepseek (auth.json) or DEEPSEEK_API_KEY.
  • Direct provider beats OpenRouter. When the configured model is an OpenRouter slug for a vendor that also has a direct BYOK provider with the same model (date-suffix tolerant, e.g. deepseek/deepseek-v4-flash vs deepseek/deepseek-v4-flash:free), requests route straight to the official API instead of the relay.
  • Tool-schema normalization. DeepSeek (and OpenAI-compatible gateways) now get tool schemas flattened at the provider boundary: zod discriminated-union oneOf shapes become a plain type:"object", and constraint keywords their strict validators reject (minimum, pattern, minLength, …) are stripped. Fixes HTTP 400 Invalid schema for function 'compute_job'.
  • compute_job contract flattened. The tool's schema is now a plain object schema with job_id gated at runtime.
  • DeepSeek-v4 thinking control. Non-reasoning v4 models get thinking:{type:"disabled"}; small calls (titles/summaries/compaction) disable thinking; variants expose low/medium/high/max via reasoningEffort.

Tests

Added deepseek.test.ts (resolution, base URL override, direct-beats-OpenRouter incl. unauthenticated shadow guard, small_model routing), tool-schema.test.ts, and transform-deepseek.test.ts. Full CLI suite: no regressions vs baseline (1734 pass vs 1704 baseline; the remaining failures are pre-existing Windows sandbox/teardown flakiness).

Notes

  • Dependency pinned to @ai-sdk/deepseek@1.0.50 (the last V2-language-model-spec version, compatible with ai@5.0.119; the 3.x line targets the V4 spec and is incompatible).
  • Verified end-to-end against the official API: pingpong 🏓 over the direct route, and a tool-loop session (glob) with no schema 400s.

DeepSeek was routed through the generic OpenAI-compatible adapter, which
mishandled V4's reasoning and strict tool-schema validation. Add a native
@ai-sdk/deepseek adapter and the supporting plumbing:

- Resolve the native adapter for the deepseek provider in both npm-resolution
  chains (models.dev ingestion + config-provider merge), so deepseek-v4 models
  use the V2-spec adapter that replays reasoning_content across tool loops.
- Add a deepseek CUSTOM_LOADER that pins the official endpoint
  (https://api.deepseek.com), honors DEEPSEEK_BASE_URL, and resolves the key
  from auth.json or DEEPSEEK_API_KEY.
- Direct-provider-beats-OpenRouter: when the configured model is an OpenRouter
  slug for a vendor that also has a direct BYOK provider with the same model
  (date-suffix tolerant), prefer the official API route over the relay.
- Normalize tool schemas at the provider boundary for DeepSeek/OpenAI-
  compatible gateways: flatten zod discriminated-union oneOf shapes into a
  plain type:"object" and strip constraint keywords their strict validators
  reject (fixes HTTP 400 "schema must be of type object" on compute_job).
- Flatten the compute_job tool contract to a plain object schema and gate
  job_id at runtime, matching the normalized wire shape.
- DeepSeek-v4 thinking control: non-reasoning v4 models get
  thinking:{type:"disabled"} so agent calls don't silently reason; small calls
  (titles/summaries/compaction) disable thinking on the flash model; variants
  expose low/medium/high/max reasoningEffort.

Tests: deepseek resolution (native adapter, base URL override, direct-beats-
OpenRouter incl. unauthenticated shadow guard, small_model routing), tool-schema
normalization, and transform variants/options/smallOptions. Full CLI suite shows
no regressions vs baseline.

Co-Authored-By: Claude <noreply@anthropic.com>
@vercel

vercel Bot commented Aug 12, 2026

Copy link
Copy Markdown

qpdv (@qpd-v) is attempting to deploy a commit to the InkVell Team on Vercel.

A member of the Team first needs to authorize it.

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.

1 participant