#7738·cc-switch

Antigravity streamGenerateContent succeeds but is not recorded in usage statistics

Author: yuanyuan2233Created Sep 28, 2026Updated Sep 28, 2026
Labelsbug

Self Checks / 自检

CC Switch Version / 版本号

3.20.4

Operating System / 操作系统

Windows

Related App / 涉及应用

Other / 其他

Steps to Reproduce / 重现步骤

  1. Configure Antigravity to use CC Switch as the Gemini API endpoint: http://127.0.0.1:15721

  2. Use the Gemini provider: local-newapi-sub2api-antigravity-gemini

  3. Send a non-streaming request: POST /v1beta/models/gemini-3.8-flash:generateContent

  4. Confirm that the request succeeds and is immediately recorded in CC Switch usage statistics.

  5. Use Antigravity normally, which sends a streaming request: POST /v1beta/models/gemini-3.8-flash:streamGenerateContent

  6. Confirm that the streaming request succeeds.

  7. Check the upstream New API logs and confirm that the request and token usage are recorded correctly.

  8. Check CC Switch usage statistics.

  9. No new usage record is created for the successful streaming request.

Expected Behavior / 期望行为

Successful Antigravity streamGenerateContent requests should be written to proxy_request_logs and included in CC Switch usage statistics after the stream finishes.

Actual Behavior / 实际行为

The Antigravity streaming request is proxied successfully and completes normally, but CC Switch does not create a corresponding usage/statistics record.

Non-streaming generateContent requests using the same provider and model are recorded correctly.

Additional Context / 补充信息

Relevant Logs & Evidence

1. Baseline: Non-streaming generateContent succeeds and is recorded correctly

CC Switch Log (cc-switch.log):

log
[2026-09-28][19:32:19][DEBUG][cc_switch_lib::proxy::forwarder] [CacheTrace] app=gemini, provider=<redacted-provider>, endpoint=/v1beta/models/gemini-3.8-flash:generateContent, api_format=native, session_client_provided=false, prompt_cache_key=absent, store=absent, stream=absent, instructions_hash=absent, system_hash=absent, tools_hash=absent, input_hash=absent, messages_hash=absent, include_hash=absent, cache_controls=count=0,ttls=none, body_hash=<redacted>

[2026-09-28][19:32:19][INFO][cc_switch_lib::proxy::forwarder] [Gemini] >>> 目标: http://127.0.0.1:3000/v1beta/models/gemini-3.8-flash:generateContent (model=<none>)

[2026-09-28][19:32:22][DEBUG][cc_switch_lib::proxy::response_processor] [Gemini] 已接收响应头: status=200, bytes=558, headers=[connection, content-length=558, content-type=application/json, date, referrer-policy, x-client-request-id, x-content-type-options, x-frame-options, x-new-api-version, x-oneapi-request-id, x-request-id=<redacted>]

[2026-09-28][19:32:22][DEBUG][cc_switch_lib::proxy::response_processor] [Gemini] 响应体已接收: bytes=558 (content omitted)

[2026-09-28][19:32:22][DEBUG][cc_switch_lib::proxy::response_processor] [gemini] 插入日志: id=<redacted-request-id>, provider=<redacted-provider>, model=gemini-3.8-flash, streaming=false, status=200, latency_ms=2687, first_token_ms=None, session=<redacted-session-id>, input=258, output=19, cache_read=0, cache_creation=0

Database Verification (proxy_request_logs):

json
{
  "request_id": "<redacted-request-id>",
  "provider_id": "<redacted-provider>",
  "app_type": "gemini",
  "model": "gemini-3.8-flash",
  "is_streaming": 0,
  "status_code": 200,
  "input_tokens": 258,
  "output_tokens": 19,
  "total_cost_usd": "0.00026475",
  "latency_ms": 2687,
  "created_at": 1790595142
}

──────

2. Bug: Streaming streamGenerateContent succeeds upstream but is missing in CC Switch

Upstream New API Log
(Confirms 200 OK, full SSE stream, and token usage):

log
[GIN] 2026/09/28 - 20:00:53 | relay | <redacted-request-id> | 200 | 6.1296027s | 127.0.0.1 | POST /v1beta/models/gemini-3.8-flash:streamGenerateContent?alt=sse

[INFO] 2026/09/28 - 20:00:53 | <redacted-request-id> | stream ended: reason=eof

[INFO] 2026/09/28 - 20:00:53 | <redacted-request-id> | record consume log: userId=<redacted>, params={
  "channel_id": "<redacted>",
  "prompt_tokens": 163766,
  "completion_tokens": 142,
  "model_name": "gemini-3.8-flash",
  "token_name": "<redacted>",
  "quota": 6162525,
  "content": "",
  "token_id": "<redacted>",
  "use_time_seconds": 6,
  "is_stream": true,
  "group": "default",
  "other": {
    "admin_info": {
      "use_channel": ["<redacted>"]
    },
    "billing_source": "wallet",
    "cache_ratio": 1,
    "cache_tokens": 160660,
    "completion_ratio": 4,
    "frt": 6032,
    "group_ratio": 1,
    "is_model_mapped": true,
    "model_price": -1,
    "model_ratio": 37.5,
    "request_conversion": ["Google Gemini"],
    "request_path": "/v1beta/models/gemini-3.8-flash:streamGenerateContent",
    "stream_status": {
      "end_reason": "eof",
      "status": "ok"
    },
    "upstream_model_name": "gemini-3.8-flash-high",
    "user_group_ratio": -1
  }
}

CC Switch Log (cc-switch.log):

log
[2026-09-28][17:15:06][INFO][cc_switch_lib::proxy::forwarder] [Gemini] >>> 目标: http://127.0.0.1:3000/v1beta/models/gemini-3.8-flash:streamGenerateContent (model=<none>)

Note: Forwarding happens normally, but after the stream completes and the client finishes rendering, no [response_processor] log appears and no [gemini] 插入日志 entry is generated.

──────

3. Database Check (proxy_request_logs)

sql
SELECT request_id, model, is_streaming, status_code, created_at
FROM proxy_request_logs
WHERE app_type = 'gemini'
ORDER BY created_at DESC
LIMIT 5;

Result:

Only the non-streaming call (is_streaming=0) from 19:32:22 exists.

None of the subsequent successful streamGenerateContent requests (is_streaming=1) were written to the database.

──────

4. Suspected Cause

In Gemini native API streaming:

/v1beta/models/{model}:streamGenerateContent?alt=sse
  • usageMetadata (promptTokenCount, candidatesTokenCount) is delivered in the last SSE data chunk.
  • CC Switch's response processor appears to neither track SSE termination nor parse the trailing usage payload for native Gemini endpoints, causing the usage logging step to be skipped entirely.