Skip to content

Improve detection accuracy for non-OpenAI providers#1

Open
jimbb wants to merge 1 commit into
mir-xiong:mainfrom
jimbb:improve-detection-accuracy
Open

Improve detection accuracy for non-OpenAI providers#1
jimbb wants to merge 1 commit into
mir-xiong:mainfrom
jimbb:improve-detection-accuracy

Conversation

@jimbb
Copy link
Copy Markdown

@jimbb jimbb commented Apr 1, 2026

Summary

Fixes false negatives when detecting OpenAI-compatible APIs from non-OpenAI providers.

Changes

1. Parse JSON regardless of Content-Type header

Some providers (e.g., Alibaba Bailian) return valid JSON responses without setting Content-Type: application/json. The tool now attempts to parse JSON on all responses.

2. Detect "model not supported" errors as valid API detection

When the probe model (gpt-4o-mini) is not available on the provider but the API is otherwise working, the tool now reports:

  • supported: true
  • errorType: "model_not_found"
  • Message suggesting available models or /v1/models endpoint

Before:

{"supported": false, "message": "Chat Completions API was not detected."}

After:

{"supported": true, "confidence": "medium", "errorType": "model_not_found", "message": "API detected, but model 'gpt-4o-mini' not available. Check /v1/models for available models."}

3. Detect payment/credit errors as valid API detection

402/403/429 errors with payment-related keywords now report as API detected with payment issue, rather than "not detected".

Before:

{"supported": false, "message": "Chat Completions API was not detected."}

After:

{"supported": true, "confidence": "medium", "errorType": "payment", "message": "Insufficient credits. Add more using https://openrouter.ai/settings/credits"}

New Error Types

  • model_not_found - API exists but probed model not available
  • payment - API exists but payment/credit issue

Testing

Provider Before After
Alibaba Bailian ❌ Not detected ✅ Detected (model_not_found)
OpenRouter (no credits) ❌ Not detected ✅ Detected (payment)
NavaClaude (expired) ✅ Detected (auth) ✅ Detected (auth)
OpenAI ✅ Detected ✅ Detected

Fixes false negatives when detecting OpenAI-compatible APIs:

1. Parse JSON regardless of Content-Type header
   - Some providers (e.g., Alibaba Bailian) return JSON without
     setting the proper Content-Type header
   - Now attempts JSON.parse on all responses

2. Detect "model not supported" errors as valid API detection
   - When probing with gpt-4o-mini fails because the provider uses
     different model names (e.g., glm-5), report as "API detected but
     model not available" instead of "not detected"
   - New errorType: 'model_not_found'

3. Detect payment/credit errors as valid API detection
   - 402/403/429 errors with payment-related keywords now report as
     "API detected but payment issue" instead of "not detected"
   - New errorType: 'payment'
   - Supports English and Chinese payment error messages

4. Provide model hints in error messages
   - When model not found, suggests checking /v1/models or lists
     available models

Tested with:
- OpenAI (working)
- Alibaba Bailian (was false negative, now correctly detected)
- OpenRouter (payment issue, now correctly detected)
- NavaClaude (account expired, correctly detected)
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