feat: add NEAR AI provider integration (#1594)

* feat: add NEAR AI provider integration

- Create vendor, brand, and model descriptors for NEAR AI (22 models)
- Add NEAR AI to route metadata, client, provider auto-detect, and profiles
- Update compatibility tests and ProviderManager test PRESET_ORDER
- Add README and docs entries for NEAR AI provider
- Update .env.example with NEAR AI configuration

* fix: address CodeRabbit review comments

- Fix .env.example: change 'Option N' to 'Option 11' in quick reference
- Narrow isNearaiModelName to use explicit NearAI model prefixes instead of broad includes('/')
- Add NEARAI_API_KEY propagation in strictEnv startup path

* fix: align NEAR AI validation host matching with wildcard subdomain routing

- Add *.completions.near.ai to matchBaseUrlHosts in vendor descriptor
- Add matchHostnameAgainstRouteHosts helper with wildcard (*.) prefix support
- Use helper in both resolveRouteIdFromBaseUrl and getRuntimeValidationTarget
- Add regression test for qwen35-122b.completions.near.ai TEE endpoint
- Add NEARAI_API_KEY to test env cleanup list

* fix: align Near AI integration with env-only provider best practices

- Replace loose .includes('near.ai') with isNearaiBaseUrl() in providerProfiles.ts
  for exact hostname validation (all 4 instances)
- Add NEARAI_API_KEY to copiedOpenAIKeyProvider detection in providerFlag.ts
- Add case 'nearai' to applyProviderFlag switch with dedicated key precedence
- Add 'nearai' to PREFERRED_PROVIDER_ORDER
- Add useNearaiEnvOnlyProvider to OpenAI shim condition in client.ts
- Remove OPENAI_API_KEY exclusion from hasNearaiEnvOnlyProviderIntent (dedicated
  key wins over stale generic key, consistent with xAI pattern)
- Update detection priority comment in providerAutoDetect.ts to include
  MIMO_API_KEY, XAI_API_KEY, and NEARAI_API_KEY

* fix: add exact completions.near.ai host to isNearaiBaseUrl

* fix: add higher-precedence provider key exclusions to hasNearaiEnvOnlyProviderIntent

* fix: add OPENAI_API_KEY and MINIMAX_API_KEY exclusions to hasNearaiEnvOnlyProviderIntent

* fix(near-ai): don't let stale OPENAI_API_KEY suppress Near AI routing

---------

Co-authored-by: Gravirei <gravirei@users.noreply.github.com>
This commit is contained in:
Gravirei
2026-06-11 12:09:25 +08:00
committed by GitHub
co-authored by Gravirei
parent d00b1050f5
commit eacc7d8fac
18 changed files with 748 additions and 16 deletions
+19
View File
@@ -30,6 +30,10 @@
# OPENAI_MODEL=gpt-4o
# OPENAI_BASE_URL=https://api.openai.com/v1 (optional)
#
# Option 11 — NEAR AI (unified gateway: Claude, GPT, Gemini + TEE models):
# NEARAI_API_KEY=your_key_here
# OPENAI_MODEL=anthropic/claude-sonnet-4-6 (optional, default)
#
# Option 3 — Google Gemini:
# CLAUDE_CODE_USE_GEMINI=1
# GEMINI_API_KEY=your-gemini-key-here
@@ -287,6 +291,21 @@ ANTHROPIC_API_KEY=sk-ant-your-key-here
# ANTHROPIC_MODEL=MiniMax-M2.7
# -----------------------------------------------------------------------------
# Option 11: NEAR AI
# -----------------------------------------------------------------------------
# NEAR AI is a unified OpenAI-compatible gateway to Claude, GPT, Gemini,
# and TEE-hosted open models — all under one API key.
# Get your API key from https://cloud.near.ai/dashboard/organizations
#
# NEARAI_API_KEY=your-nearai-key-here
# OPENAI_BASE_URL=https://cloud-api.near.ai/v1 (optional, default)
# OPENAI_MODEL=anthropic/claude-sonnet-4-6 (optional, default)
#
# For direct TEE completions (lower latency + verifiable privacy):
# OPENAI_BASE_URL=https://qwen35-122b.completions.near.ai/v1
# =============================================================================
# OPTIONAL TUNING
# =============================================================================