File size: 7,271 Bytes
69fec20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
================================================================================  
GeminiCli API 测试
================================================================================  

================================================================================  
【测试1】流式请求 (stream_request with native=False)
================================================================================  
请求体: {
  "model": "gemini-2.5-flash",
  "request": {
    "contents": [
      {
        "role": "user",
        "parts": [
          {
            "text": "Hello, tell me a joke in one sentence."
          }
        ]
      }
    ]
  }
}

流式响应数据 (每个chunk):
--------------------------------------------------------------------------------  
[2026-01-10 09:55:29] [INFO] SQLite storage initialized at ./creds\credentials.db 
[2026-01-10 09:55:29] [INFO] Using SQLite storage backend
[2026-01-10 09:55:31] [INFO] Token刷新成 功并已保存: my-project-9-481103-1765596755.json (mode=geminicli)
[2026-01-10 09:55:34] [INFO] [DB] 准备commit,总更新行数=1
[2026-01-10 09:55:34] [INFO] [DB] commit 完成
[2026-01-10 09:55:34] [INFO] [DB] update_credential_state 结束: success=True, updated_count=1

Chunk #1:
  类型: str
  长度: 626
  内容预览: 'data: {"response": {"candidates": [{"content": {"role": "model","parts": [{"text": "Why did the scarecrow win an award? Because he was outstanding in his field."}]},"finishReason": "STOP"}],"usageMeta'
  解析后的JSON: {
    "response": {
        "candidates": [
            {
                "content": {
                    "role": "model",     
                    "parts": [
                        {
                            "text": "Why did the scarecrow win an award? Because he was outstanding in his field."
                        }
                    ]
                },
                "finishReason": "STOP"   
            }
        ],
        "usageMetadata": {
            "promptTokenCount": 10,      
            "candidatesTokenCount": 17,  
            "totalTokenCount": 51,       
            "trafficType": "PROVISIONED_THROUGHPUT",
            "promptTokensDetails": [     
                {
                    "modality": "TEXT",  
                    "tokenCount": 10     
                }
            ],
            "candidatesTokensDetails": [ 
                {
                    "modality": "TEXT",  
                    "tokenCount": 17     
                }
            ],
            "thoughtsTokenCount": 24     
        },
        "modelVersion": "gemini-2.5-flash",
        "createTime": "2026-01-10T01:55:29.168589Z",
        "responseId": "kbFhaY2lCr-ZseMPqMiDmAU"
    },
    "traceId": "55650653afd3c738"        
}

Chunk #2:
  类型: str
  长度: 0
  内容预览: ''
E:\projects\gcli2api\src\api\geminicli.py:491: RuntimeWarning: coroutine 'get_auto_ban_error_codes' was never awaited      
  async for chunk in stream_request(body=test_body, native=False):
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

总共收到 2 个chunk

================================================================================  
【测试2】非流式请求 (non_stream_request) 
================================================================================  
请求体: {
  "model": "gemini-2.5-flash",
  "request": {
    "contents": [
      {
        "role": "user",
        "parts": [
          {
            "text": "Hello, tell me a joke in one sentence."
          }
        ]
      }
    ]
  }
}

[2026-01-10 09:55:35] [INFO] Token刷新成 功并已保存: gen-lang-client-0194852792-1767296759.json (mode=geminicli)
[2026-01-10 09:55:38] [INFO] [DB] 准备commit,总更新行数=1
[2026-01-10 09:55:38] [INFO] [DB] commit 完成
[2026-01-10 09:55:38] [INFO] [DB] update_credential_state 结束: success=True, updated_count=1
E:\projects\gcli2api\src\api\geminicli.py:530: RuntimeWarning: coroutine 'get_auto_ban_error_codes' was never awaited      
  response = await non_stream_request(body=test_body)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
非流式响应数据:
--------------------------------------------------------------------------------  
状态码: 200
Content-Type: application/json; charset=UTF-8

响应头: {'server': 'openresty', 'date': 'Sat, 10 Jan 2026 01:55:34 GMT', 'content-type': 'application/json; charset=UTF-8', 'transfer-encoding': 'chunked', 'connection': 'keep-alive', 'x-cloudaicompanion-trace-id': 'bf3a5eb6636774d2', 'vary': 'Origin, X-Origin, Referer', 'content-encoding': 'gzip', 'x-xss-protection': '0', 'x-frame-options': 'SAMEORIGIN', 'x-content-type-options': 'nosniff', 'server-timing': 'gfet4t7; dur=1377', 'alt-svc': 'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000', 'access-control-allow-origin': '*', 'access-control-allow-methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS', 'access-control-allow-headers': 'Content-Type, Authorization, X-Requested-With', 'cache-control': 'no-cache', 'content-length': '969'}

响应内容 (原始):
{
  "response": {
    "candidates": [
      {
        "content": {
          "role": "model",
          "parts": [
            {
              "text": "Why did the scarecrow win an award? Because he was outstanding in his field!"
            }
          ]
        },
        "finishReason": "STOP",
        "avgLogprobs": -0.54438119776108684
      }
    ],
    "usageMetadata": {
      "promptTokenCount": 10,
      "candidatesTokenCount": 17,        
      "totalTokenCount": 47,
      "trafficType": "PROVISIONED_THROUGHPUT",
      "promptTokensDetails": [
        {
          "modality": "TEXT",
          "tokenCount": 10
        }
      ],
      "candidatesTokensDetails": [       
        {
          "modality": "TEXT",
          "tokenCount": 17
        }
      ],
      "thoughtsTokenCount": 20
    },
    "modelVersion": "gemini-2.5-flash",  
    "createTime": "2026-01-10T01:55:33.450396Z",
    "responseId": "lbFhady-G7yi694PmLOP4As"
  },
  "traceId": "bf3a5eb6636774d2"
}


响应内容 (格式化JSON):
{
  "response": {
    "candidates": [
      {
        "content": {
          "role": "model",
          "parts": [
            {
              "text": "Why did the scarecrow win an award? Because he was outstanding in his field!"
            }
          ]
        },
        "finishReason": "STOP",
        "avgLogprobs": -0.5443811977610868
      }
    ],
    "usageMetadata": {
      "promptTokenCount": 10,
      "candidatesTokenCount": 17,        
      "totalTokenCount": 47,
      "trafficType": "PROVISIONED_THROUGHPUT",
      "promptTokensDetails": [
        {
          "modality": "TEXT",
          "tokenCount": 10
        }
      ],
      "candidatesTokensDetails": [       
        {
          "modality": "TEXT",
          "tokenCount": 17
        }
      ],
      "thoughtsTokenCount": 20
    },
    "modelVersion": "gemini-2.5-flash",  
    "createTime": "2026-01-10T01:55:33.450396Z",
    "responseId": "lbFhady-G7yi694PmLOP4As"
  },
  "traceId": "bf3a5eb6636774d2"
}

================================================================================  
测试完成
================================================================================