Skip to content

Commit 1d60d9b

Browse files
committed
Revert "优化反重力503报错"
This reverts commit e488d1a.
1 parent cb95af5 commit 1d60d9b

12 files changed

Lines changed: 434 additions & 13 deletions

.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ RESOURCE_MANAGER_API_URL=https://cloudresourcemanager.googleapis.com
104104
# 默认: https://serviceusage.googleapis.com
105105
SERVICE_USAGE_API_URL=https://serviceusage.googleapis.com
106106

107+
# 用于Google Antigravity API的URL (反重力模式)
108+
# 默认: https://daily-cloudcode-pa.sandbox.googleapis.com
109+
ANTIGRAVITY_API_URL=https://daily-cloudcode-pa.sandbox.googleapis.com
110+
107111
# ================================================================
108112
# 错误处理和重试配置
109113
# ================================================================

README.md

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,132 @@ curl -X POST "http://127.0.0.1:7861/v1/messages" \
615615
- 支持 Claude 的所有标准参数
616616
- 响应格式符合 Claude API 规范
617617

618+
#### 4. Antigravity API 端点
619+
620+
**支持三种格式:OpenAI、Gemini 和 Claude**
621+
622+
##### Antigravity OpenAI 格式端点
623+
624+
**端点:** `/antigravity/v1/chat/completions`
625+
**认证:** `Authorization: Bearer your_api_password`
626+
627+
**请求示例:**
628+
```bash
629+
curl -X POST "http://127.0.0.1:7861/antigravity/v1/chat/completions" \
630+
-H "Authorization: Bearer your_api_password" \
631+
-H "Content-Type: application/json" \
632+
-d '{
633+
"model": "claude-sonnet-4-5",
634+
"messages": [
635+
{"role": "user", "content": "Hello"}
636+
],
637+
"stream": true
638+
}'
639+
```
640+
641+
##### Antigravity Gemini 格式端点
642+
643+
**非流式端点:** `/antigravity/v1/models/{model}:generateContent`
644+
**流式端点:** `/antigravity/v1/models/{model}:streamGenerateContent`
645+
646+
**认证方式(任选一种):**
647+
- `Authorization: Bearer your_api_password`
648+
- `x-goog-api-key: your_api_password`
649+
- URL 参数:`?key=your_api_password`
650+
651+
**请求示例:**
652+
```bash
653+
# Gemini 格式非流式请求
654+
curl -X POST "http://127.0.0.1:7861/antigravity/v1/models/claude-sonnet-4-5:generateContent" \
655+
-H "x-goog-api-key: your_api_password" \
656+
-H "Content-Type: application/json" \
657+
-d '{
658+
"contents": [
659+
{"role": "user", "parts": [{"text": "Hello"}]}
660+
],
661+
"generationConfig": {
662+
"temperature": 0.7
663+
}
664+
}'
665+
666+
# Gemini 格式流式请求
667+
curl -X POST "http://127.0.0.1:7861/antigravity/v1/models/gemini-2.5-flash:streamGenerateContent?key=your_api_password" \
668+
-H "Content-Type: application/json" \
669+
-d '{
670+
"contents": [
671+
{"role": "user", "parts": [{"text": "Hello"}]}
672+
]
673+
}'
674+
```
675+
676+
##### Antigravity Claude 格式端点
677+
678+
**端点:** `/antigravity/v1/messages`
679+
**认证:** `x-api-key: your_api_password`
680+
681+
**请求示例:**
682+
```bash
683+
curl -X POST "http://127.0.0.1:7861/antigravity/v1/messages" \
684+
-H "x-api-key: your_api_password" \
685+
-H "anthropic-version: 2023-06-01" \
686+
-H "Content-Type: application/json" \
687+
-d '{
688+
"model": "claude-sonnet-4-5",
689+
"max_tokens": 1024,
690+
"messages": [
691+
{"role": "user", "content": "Hello"}
692+
]
693+
}'
694+
```
695+
696+
**支持的 Antigravity 模型:**
697+
- Claude 系列:`claude-sonnet-4-5`、`claude-opus-4-5` 等
698+
- Gemini 系列:`gemini-2.5-flash`、`gemini-2.5-pro` 等
699+
- 自动支持思维模型(thinking models)
700+
701+
**Gemini 原生示例:**
702+
```python
703+
from io import BytesIO
704+
from PIL import Image
705+
from google.genai import Client
706+
from google.genai.types import HttpOptions
707+
from google.genai import types
708+
# The client gets the API key from the environment variable `GEMINI_API_KEY`.
709+
710+
client = Client(
711+
api_key="pwd",
712+
http_options=HttpOptions(base_url="http://127.0.0.1:7861"),
713+
)
714+
715+
prompt = (
716+
"""
717+
画一只猫
718+
"""
719+
)
720+
721+
response = client.models.generate_content(
722+
model="gemini-3.1-flash-image",
723+
contents=[prompt],
724+
config=types.GenerateContentConfig(
725+
image_config=types.ImageConfig(
726+
aspect_ratio="16:9",
727+
)
728+
)
729+
)
730+
for part in response.candidates[0].content.parts:
731+
if part.text is not None:
732+
print(part.text)
733+
elif part.inline_data is not None:
734+
image = Image.open(BytesIO(part.inline_data.data))
735+
image.save("generated_image.png")
736+
737+
```
738+
739+
**说明:**
740+
- OpenAI 端点返回 OpenAI 兼容格式
741+
- Gemini 端点返回 Gemini 原生格式
742+
- 两种端点使用相同的 API 密码
743+
618744
## 📋 完整 API 参考
619745

620746
### Web 控制台 API

config.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"GOOGLEAPIS_PROXY_URL": "googleapis_proxy_url",
3030
"RESOURCE_MANAGER_API_URL": "resource_manager_api_url",
3131
"SERVICE_USAGE_API_URL": "service_usage_api_url",
32+
"ANTIGRAVITY_API_URL": "antigravity_api_url",
3233
"AUTO_BAN": "auto_ban_enabled",
3334
"AUTO_BAN_ERROR_CODES": "auto_ban_error_codes",
3435
"RETRY_429_MAX_RETRIES": "retry_429_max_retries",
@@ -423,6 +424,25 @@ async def get_service_usage_api_url() -> str:
423424
)
424425

425426

427+
async def get_antigravity_api_url() -> str:
428+
"""
429+
Get Antigravity API URL setting.
430+
431+
用于Google Antigravity API的URL。
432+
433+
Environment variable: ANTIGRAVITY_API_URL
434+
Database config key: antigravity_api_url
435+
Default: https://daily-cloudcode-pa.sandbox.googleapis.com
436+
"""
437+
return str(
438+
await get_config_value(
439+
"antigravity_api_url",
440+
"https://daily-cloudcode-pa.sandbox.googleapis.com",
441+
"ANTIGRAVITY_API_URL",
442+
)
443+
)
444+
445+
426446
async def get_keepalive_url() -> str:
427447
"""
428448
Get keep-alive URL setting.

docs/README_EN.md

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,132 @@ curl -X POST "http://127.0.0.1:7861/v1/messages" \
615615
- Supports all Claude standard parameters
616616
- Response format follows Claude API specification
617617

618+
#### 4. Antigravity API Endpoints
619+
620+
**Supports three formats: OpenAI, Gemini, and Claude**
621+
622+
##### Antigravity OpenAI Format Endpoints
623+
624+
**Endpoint:** `/antigravity/v1/chat/completions`
625+
**Authentication:** `Authorization: Bearer your_api_password`
626+
627+
**Request Example:**
628+
```bash
629+
curl -X POST "http://127.0.0.1:7861/antigravity/v1/chat/completions" \
630+
-H "Authorization: Bearer your_api_password" \
631+
-H "Content-Type: application/json" \
632+
-d '{
633+
"model": "claude-sonnet-4-5",
634+
"messages": [
635+
{"role": "user", "content": "Hello"}
636+
],
637+
"stream": true
638+
}'
639+
```
640+
641+
##### Antigravity Gemini Format Endpoints
642+
643+
**Non-streaming Endpoint:** `/antigravity/v1/models/{model}:generateContent`
644+
**Streaming Endpoint:** `/antigravity/v1/models/{model}:streamGenerateContent`
645+
646+
**Authentication Methods (choose one):**
647+
- `Authorization: Bearer your_api_password`
648+
- `x-goog-api-key: your_api_password`
649+
- URL parameter: `?key=your_api_password`
650+
651+
**Request Examples:**
652+
```bash
653+
# Gemini format non-streaming request
654+
curl -X POST "http://127.0.0.1:7861/antigravity/v1/models/claude-sonnet-4-5:generateContent" \
655+
-H "x-goog-api-key: your_api_password" \
656+
-H "Content-Type: application/json" \
657+
-d '{
658+
"contents": [
659+
{"role": "user", "parts": [{"text": "Hello"}]}
660+
],
661+
"generationConfig": {
662+
"temperature": 0.7
663+
}
664+
}'
665+
666+
# Gemini format streaming request
667+
curl -X POST "http://127.0.0.1:7861/antigravity/v1/models/gemini-2.5-flash:streamGenerateContent?key=your_api_password" \
668+
-H "Content-Type: application/json" \
669+
-d '{
670+
"contents": [
671+
{"role": "user", "parts": [{"text": "Hello"}]}
672+
]
673+
}'
674+
```
675+
676+
##### Antigravity Claude Format Endpoints
677+
678+
**Endpoint:** `/antigravity/v1/messages`
679+
**Authentication:** `x-api-key: your_api_password`
680+
681+
**Request Example:**
682+
```bash
683+
curl -X POST "http://127.0.0.1:7861/antigravity/v1/messages" \
684+
-H "x-api-key: your_api_password" \
685+
-H "anthropic-version: 2023-06-01" \
686+
-H "Content-Type: application/json" \
687+
-d '{
688+
"model": "claude-sonnet-4-5",
689+
"max_tokens": 1024,
690+
"messages": [
691+
{"role": "user", "content": "Hello"}
692+
]
693+
}'
694+
```
695+
696+
**Supported Antigravity Models:**
697+
- Claude series: `claude-sonnet-4-5`, `claude-opus-4-5`, etc.
698+
- Gemini series: `gemini-2.5-flash`, `gemini-2.5-pro`, etc.
699+
- Automatically supports thinking models
700+
701+
**Gemini Native Example:**
702+
```python
703+
from io import BytesIO
704+
from PIL import Image
705+
from google.genai import Client
706+
from google.genai.types import HttpOptions
707+
from google.genai import types
708+
# The client gets the API key from the environment variable `GEMINI_API_KEY`.
709+
710+
client = Client(
711+
api_key="pwd",
712+
http_options=HttpOptions(base_url="http://127.0.0.1:7861"),
713+
)
714+
715+
prompt = (
716+
"""
717+
Draw a cat
718+
"""
719+
)
720+
721+
response = client.models.generate_content(
722+
model="gemini-3.1-flash-image",
723+
contents=[prompt],
724+
config=types.GenerateContentConfig(
725+
image_config=types.ImageConfig(
726+
aspect_ratio="16:9",
727+
)
728+
)
729+
)
730+
for part in response.candidates[0].content.parts:
731+
if part.text is not None:
732+
print(part.text)
733+
elif part.inline_data is not None:
734+
image = Image.open(BytesIO(part.inline_data.data))
735+
image.save("generated_image.png")
736+
737+
```
738+
739+
**Notes:**
740+
- OpenAI endpoints return OpenAI-compatible format
741+
- Gemini endpoints return Gemini native format
742+
- Both endpoints use the same API password
743+
618744
## 📋 Complete API Reference
619745

620746
### Web Console API

0 commit comments

Comments
 (0)