Skip to content

feat(importer): review ai points job calls models through the dos.ai gateway - #1607

Merged
JOY (JOY) merged 2 commits into
devfrom
feat/1531-review-ai-points-dos-ai
Nov 4, 2026
Merged

JOY (JOY) merged 2 commits into
devfrom
feat/1531-review-ai-points-dos-ai

Conversation

@JOY

@JOY JOY (JOY) commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Refs #1531

On 2026-11-04 JOY changed D2 of Docs/Proposals/2026-11-03-ai-review-points.html: "Tại sao khóa Anthropic? Tao có nguyên 1 cái dos.ai cơ mà?". The review AI points job (#1599) therefore calls models through JOY's dos.ai gateway instead of the Anthropic API.

What the gateway offers

Read from the DOS/DOS.AI source, services/api-gateway:

  • An OpenAI-compatible Files and Batch API:
    • POST /v1/files (multipart, purpose=batch);
    • POST /v1/batches (endpoint /v1/chat/completions, completion_window 24h);
    • GET /v1/batches/:id, POST /v1/batches/:id/cancel;
    • GET /v1/files/:id/content (JSONL output).
  • Price: batch lines are billed at 0.5x. Prices are dos.ai list prices with zero markup.
  • Models in the Batch API: only dos (Qwen3.8 27B on DOS GPUs), qwen3.8-* and deepseek-*. Claude is not served there.
  • Auth: dos_sk_ keys sent as Authorization: Bearer, as the importer's other AI clients already do (DOS_AI_API_KEY, DOS_AI_BASE_URL).
  • No credits: the gateway answers 402.
  • Privacy: a batch under a Zero Data Retention organization is refused.

The change

  • dosAiReviewAiClient replaces the Anthropic SDK client, and @anthropic-ai/sdk is removed.

    • Requests are OpenAI batch lines with response_format: json_schema (strict), temperature: 0, max_tokens: 6000, the instructions as the system message and the reviews as the user message.
    • finish_reason length is treated as cut off, and content_filter as refused. Both, and any errored line, are stored as failed, never as empty.
  • Models (D1's shape): dos by default and qwen3.8-max as the fallback if dos misses the gold set.

    • Prices: $0.25/$1.50 and $2/$6 per million tokens, halved for batch.
    • Caps: $5 and $15 a month.
    • Cached tokens count at the full input price, an upper bound; dos.ai's ledger is the bill.
  • Unchanged: the 2000-reviews-a-run limit, the kill switch, process-once, the persisted batch id, the evidence checks, the quality stops and --purge.

  • Review fixes: a fresh-context Claude review found 1 P1 and 3 P2. All are fixed:

    • P1: POST /batches is never retried on a lost answer, because a retry could create and bill a second batch. Only a 429 is retried.
    • P2: a batch that failed as a whole (no output), or whose output file is gone (404), closes its row and stores nothing, so its reviews are due again without spending an attempt. A line the gateway skipped for lack of credits is "unbilled", not failed.
    • P2: each call's timeout now also covers reading the response body.
  • The proposal: sections 3, 4, 5, D2 and the Rate-Services line now record the change.

  • Tests (fake gateway, no network):

    • upload, create, status, results and cancel;
    • create sent once on a network error and on a 502; retry on 429;
    • failed and purged batches; 402 lines;
    • the request body.

    Typecheck and lint pass.

Runbook for Rate-Services (replaces the earlier one)

  • Secret: DOS_AI_API_KEY, a dos_sk_ key from dev.dos.me for the DOS.AI product. It replaces ANTHROPIC_API_KEY. The key's organization must not have Zero Data Retention on, because the Batch API refuses those batches.
  • Optional: DOS_AI_BASE_URL. The default is https://api.dos.me/v1; use https://beta-api.dos.ai/v1 for Beta.
  • Variables: REVIEW_AI_POINTS_ENABLED=true (kill switch) and REVIEW_AI_MODEL (dos by default, or qwen3.8-max).
  • Order, flags and exit codes: as before. qwen3.8-max batches may wait for Alibaba's off-peak window (16:00 to 02:00 UTC). A batch still running is collected on the next run.
  • First paid run: one small --apply --max 20 on Beta. It checks that dos returns schema JSON within max_tokens (Qwen3 may spend tokens on thinking) before the gold set runs.

No model was called during development.

🤖 Generated with Claude Code


📌 TL;DR

This PR migrates the AI review extraction job from the Anthropic SDK to the dos.ai gateway's OpenAI-compatible Batch API, replacing Claude models with dos and qwen3.8-max. It updates the client implementation, request formatting, cost calculations, and environment configuration to align with the new provider's constraints and pricing.

🎯 Type of Change

  • 🚀 New feature
  • 🐛 Bugfix
  • 🧹 Refactor
  • ⚡ Performance
  • 📚 Documentation
  • ⚙️ CI / Configuration

🔍 Changes Walkthrough

File Summary of Changes
Docs/Proposals/2026-11-03-ai-review-points.html Updated the design proposal to reflect the decision (D2) to use dos.ai instead of Anthropic. Documented new model options (dos, qwen3.8-max), pricing adjustments, and API key changes.
apps/importer/.env.example Added DOS_AI_BASE_URL, REVIEW_AI_POINTS_ENABLED, and REVIEW_AI_MODEL variables. Updated comments to clarify that DOS_AI_API_KEY is now the required credential for this job.
apps/importer/package.json Removed the @anthropic-ai/sdk dependency as it is no longer used.
apps/importer/src/shopee/__tests__/review-ai-points.test.ts Updated tests to verify the new dos.ai client behavior, including batch creation via file upload, result parsing, error handling (402, 404), and cost calculations for the new models.
apps/importer/src/shopee/jobs/review-ai-points.ts Replaced the Anthropic client with a custom dosAiReviewAiClient that implements the OpenAI Batch API (file upload, batch creation, polling, result retrieval). Updated BatchRequest structure to OpenAI format. Added handling for BatchGoneError and "unbilled" (402) states.
apps/importer/src/shopee/review-ai-prompt.ts Updated REVIEW_AI_MODELS to define dos and qwen3.8-max with their specific pricing and monthly caps. Adjusted cache cost factors to 1.0 (upper bound) since dos.ai does not publish specific cache rates.

📊 Architectural Flow

sequenceDiagram
    participant Job as review-ai-points.ts
    participant Client as dosAiReviewAiClient
    participant Gateway as dos.ai Gateway
    participant DB as Supabase

    Job->>Client: createBatch(requests)
    Client->>Gateway: POST /files (JSONL)
    Gateway-->>Client: file_id
    Client->>Gateway: POST /batches (file_id)
    Gateway-->>Client: batch_id
    
    loop Polling
        Job->>Client: batchStatus(batch_id)
        Client->>Gateway: GET /batches/{id}
        Gateway-->>Client: status
    end
    
    Job->>Client: results(batch_id)
    Client->>Gateway: GET /batches/{id}
    Gateway-->>Client: output_file_id
    Client->>Gateway: GET /files/{output_file_id}/content
    Gateway-->>Client: JSONL Results
    
    Client-->>Job: BatchResult[]
    Job->>DB: Store results & update batch status
Loading

JOY (JOY) and others added 2 commits November 4, 2026 12:03
…gateway

JOY decided on 2026-11-04 that the job uses dos.ai, not the Anthropic API
(D2 of the AI review points design). The job now sends its batch through
the gateway's OpenAI-compatible Files and Batch API with DOS_AI_API_KEY
(DOS_AI_BASE_URL overrides the URL). That Batch API serves dos, qwen3.8
and deepseek models only, so the default model is dos (Qwen3.8 27B on DOS
GPUs) and qwen3.8-max is the fallback, with the same monthly caps.

Caps, kill switch, process-once, evidence checks and quality stops are
unchanged. A cut-off or filtered answer (finish_reason length or
content_filter) and an errored line are stored as failed. Cached tokens
count at the full input price, an upper bound. @anthropic-ai/sdk is
removed. The proposal notes the D2 change.

Refs #1531

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review findings on the dos.ai client (#1531):
- POST /batches is retried only on 429; a lost answer throws and says a
  batch may exist, instead of creating and billing a second one.
- A batch failed as a whole, one with no output, or one whose output file
  is gone (404) closes its row and stores nothing, so its reviews are due
  again without spending an attempt; a line not run for want of credits
  is unbilled, not failed.
- Each call's timeout covers reading the body.
- Tests: create-once on a network error and a 502, retry on 429, failed
  and purged batches, 402 lines, the request body; batch ids renamed.
- The proposal notes the dos.ai batch path in sections 4 and 5.

Refs #1531

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

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Code review skipped — your organization has no extra usage available to pay for this review.

If your organization's extra usage balance is empty, an organization admin can add extra usage credits at claude.ai/admin-settings/usage. If its monthly spend limit was reached, an admin can raise it on the same page. If neither applies, contact Anthropic support.

Once extra usage is available, someone with write access to this repository can comment @claude review on this pull request to trigger a review.

@vercel

vercel Bot commented Nov 4, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
rate Ready Ready Preview Nov 4, 2026 5:31am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Nov 4, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 19 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2210c893-08f6-4e5a-a9de-6bba2b05e7b8
Commits

Reviewing files that changed from the base of the PR and between 8919776 and bfe87d6.

Files ignored due to path filters: 1
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing: 6
  • Docs/Proposals/2026-11-03-ai-review-points.html
  • apps/importer/.env.example
  • apps/importer/package.json
  • apps/importer/src/shopee/__tests__/review-ai-points.test.ts
  • apps/importer/src/shopee/jobs/review-ai-points.ts
  • apps/importer/src/shopee/review-ai-prompt.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions github-actions Bot added docs Documentation changes area:crawlers labels Nov 4, 2026
dos[bot]
dos Bot approved these changes Nov 4, 2026

@dos dos Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⏱️ Code Review completed (6 eligible files · 50,477 chars · 3 model call(s) · 2 PR unit(s))

Whole diff with bounded context at base 37ea3c8 / head bfe87d6.
Excluded by noise policy: pnpm-lock.yaml.

✅ No verified defects

1 possible issue(s) could not be grounded in or verified against the snapshot source, so they are not published.

Context investigation was bounded to the explicitly requested snapshot paths.

🔒 Dependency check

✅ Passed. Every new package version comes from the public registry or a source this lockfile already used for it, its checksum is pinned where the format records one, and OSV lists no new malicious package or high or critical vulnerability for the versions it was asked about.

@JOY
JOY (JOY) merged commit d50de0d into dev Nov 4, 2026
18 checks passed
@JOY
JOY (JOY) deleted the feat/1531-review-ai-points-dos-ai branch November 4, 2026 05:41
@JOY JOY (JOY) mentioned this pull request Nov 6, 2026
3 of 6 tasks

This branch was successfully deployed

1 active deployment
Preview — bfe87d66 Deployed Nov 4, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:crawlers docs Documentation changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant