### Clone Repository and Install Dependencies Source: https://github.com/ibuhub/aistudiotoapi/blob/main/README.md Clone the repository and install project dependencies using npm. This is the first step for direct local setup. ```bash git clone https://github.com/iBUHub/AIStudioToAPI.git cd AIStudioToAPI ``` ```bash npm install ``` -------------------------------- ### Start the API Service Source: https://github.com/ibuhub/aistudiotoapi/blob/main/README.md Start the API service after setup. The service will be accessible at http://localhost:7860, and a web console is available at the same address for monitoring. ```bash npm start ``` -------------------------------- ### Get System Status Source: https://context7.com/ibuhub/aistudiotoapi/llms.txt Retrieve detailed system status information, including account details, configuration, and active contexts. Requires authentication. ```bash curl http://localhost:2048/api/status \ -H "Authorization: Bearer your-api-key" ``` -------------------------------- ### OpenAI Chat Completions with Function Calling Source: https://context7.com/ibuhub/aistudiotoapi/llms.txt Example of a chat completion request that includes tool definitions for function calling. The 'tool_choice' parameter controls whether the model should call a function. ```bash curl -X POST http://localhost:2048/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer your-api-key" \ -d '{ "model": "gemini-2.5-flash", "messages": [ {"role": "user", "content": "北京今天的天气怎么样?"} ], "tools": [ { "type": "function", "function": { "name": "get_weather", "description": "获取指定城市的天气信息", "parameters": { "type": "object", "properties": { "city": { "type": "string", "description": "城市名称" } }, "required": ["city"] } } } ], "tool_choice": "auto" }' ``` -------------------------------- ### List Models (OpenAI Compatible) Source: https://github.com/ibuhub/aistudiotoapi/blob/main/README.md Use this GET endpoint to retrieve a list of available models compatible with the OpenAI API format. ```http GET /v1/models ``` -------------------------------- ### Generate TTS with cURL Source: https://github.com/ibuhub/aistudiotoapi/blob/main/docs/zh/api-examples.md Examples for generating audio from text using default settings, specific voices, or multi-speaker configurations. ```bash curl -X POST http://localhost:7860/v1beta/models/gemini-2.5-flash-preview-tts:generateContent \ -H "Content-Type: application/json" \ -H "Authorization: Bearer your-api-key-1" \ -d '{ "contents": [ { "role": "user", "parts": [ { "text": "你好,这是一个语音合成测试。" } ] } ], "generationConfig": { "responseModalities": ["AUDIO"] } }' ``` ```bash curl -X POST http://localhost:7860/v1beta/models/gemini-2.5-flash-preview-tts:generateContent \ -H "Content-Type: application/json" \ -H "Authorization: Bearer your-api-key-1" \ -d '{ "contents": [ { "role": "user", "parts": [ { "text": "你好,这是一个语音合成测试。" } ] } ], "generationConfig": { "responseModalities": ["AUDIO"], "speechConfig": { "voiceConfig": { "prebuiltVoiceConfig": { "voiceName": "Kore" } } } } }' ``` ```bash curl -X POST http://localhost:7860/v1beta/models/gemini-2.5-flash-preview-tts:generateContent \ -H "Content-Type: application/json" \ -H "Authorization: Bearer your-api-key-1" \ -d '{ "contents": [ { "role": "user", "parts": [ { "text": "TTS the following conversation between Joe and Jane:\nJoe: How are you today Jane?\nJane: I am doing great, thanks for asking!" } ] } ], "generationConfig": { "responseModalities": ["AUDIO"], "speechConfig": { "multiSpeakerVoiceConfig": { "speakerVoiceConfigs": [ { "speaker": "Joe", "voiceConfig": { "prebuiltVoiceConfig": { "voiceName": "Charon" } } }, { "speaker": "Jane", "voiceConfig": { "prebuiltVoiceConfig": { "voiceName": "Kore" } } } ] } } } }' ``` -------------------------------- ### Health Check Response Example Source: https://context7.com/ibuhub/aistudiotoapi/llms.txt An example of the JSON response received from the health check endpoint, indicating the server's status. ```json { "status": "ok", "browserConnected": true, "uptime": 3600.123, "timestamp": "2025-01-15 10:30:45.123 [Asia/Shanghai]" } ``` -------------------------------- ### Anthropic Claude Messages Request with Thinking Mode Source: https://context7.com/ibuhub/aistudiotoapi/llms.txt Example of a messages request that enables 'Thinking Mode' for more complex reasoning. Specify the 'budget_tokens' to control the thinking process. ```bash curl -X POST http://localhost:2048/v1/messages \ -H "Content-Type: application/json" \ -H "x-api-key: your-api-key" \ -H "anthropic-version: 2023-06-01" \ -d '{ "model": "gemini-2.5-pro", "max_tokens": 16000, "thinking": { "type": "enabled", "budget_tokens": 10000 }, "messages": [ {"role": "user", "content": "设计一个高并发的分布式系统架构"} ] }' ``` -------------------------------- ### Run Docker Container (Command Line) Source: https://github.com/ibuhub/aistudiotoapi/blob/main/README.md Deploy the service using a Docker command. This command maps the host port 7860 to the container port, mounts a volume for authentication files, and sets environment variables for API keys and timezone. ```bash docker run -d \ --name aistudio-to-api \ -p 7860:7860 \ -v /path/to/auth:/app/configs/auth \ -e API_KEYS=your-api-key-1,your-api-key-2 \ -e TZ=Asia/Shanghai \ --restart unless-stopped \ ghcr.io/ibuhub/aistudio-to-api:latest ``` -------------------------------- ### 运行自动登录脚本 Source: https://github.com/ibuhub/aistudiotoapi/blob/main/docs/zh/auto-fill-guide.md 执行 npm 命令启动账号设置脚本,根据控制台提示选择账号进行自动填充。 ```bash npm run setup-auth ``` -------------------------------- ### Create Response with Reasoning Configuration Source: https://context7.com/ibuhub/aistudiotoapi/llms.txt This endpoint allows for response generation with specific reasoning configurations, such as setting the effort level. ```bash curl -X POST http://localhost:2048/v1/responses \ -H "Content-Type: application/json" \ -H "Authorization: Bearer your-api-key" \ -d '{ "model": "gemini-2.5-pro", "input": "设计一个电商系统的数据库架构", "reasoning": { "effort": "high" } }' ``` -------------------------------- ### 启用 Nginx 配置 Source: https://github.com/ibuhub/aistudiotoapi/blob/main/docs/zh/nginx-setup.md 通过创建符号链接并重启服务来应用 Nginx 配置。 ```bash # 创建符号链接以启用站点 sudo ln -s /etc/nginx/sites-available/aistudio-api /etc/nginx/sites-enabled/ # 检查一下配置是否正确 sudo nginx -t # 重启 Nginx sudo systemctl restart nginx ``` -------------------------------- ### 配置账号 CSV 文件 Source: https://github.com/ibuhub/aistudiotoapi/blob/main/docs/zh/auto-fill-guide.md 在项目根目录创建 users.csv 文件,按 email 和 password 的格式存储账号信息。 ```csv email,password your-email-1@gmail.com,your-password-1 your-email-2@gmail.com,your-password-2 ``` -------------------------------- ### Build Docker Image from Source Source: https://github.com/ibuhub/aistudiotoapi/blob/main/README.md Build a custom Docker image from the project's source code. This allows for local image creation before running the container. ```bash docker build -t aistudio-to-api . ``` -------------------------------- ### Create Response with Basic Input Source: https://context7.com/ibuhub/aistudiotoapi/llms.txt Use this endpoint to generate responses compatible with OpenAI's Response API format. It supports complex interaction patterns. ```bash curl -X POST http://localhost:2048/v1/responses \ -H "Content-Type: application/json" \ -H "Authorization: Bearer your-api-key" \ -d '{ "model": "gemini-2.5-flash", "input": "解释什么是RESTful API" }' ``` -------------------------------- ### Switch to Next Account Source: https://context7.com/ibuhub/aistudiotoapi/llms.txt Manually switch to the next available account in the list. Requires authentication and JSON content. ```bash curl -X PUT http://localhost:2048/api/accounts/current \ -H "Content-Type: application/json" \ -H "Authorization: Bearer your-api-key" \ -d '{}' ``` -------------------------------- ### OpenAI 兼容 API 图像生成 Source: https://github.com/ibuhub/aistudiotoapi/blob/main/docs/zh/api-examples.md 使用 gemini-2.5-flash-image 模型通过 chat/completions 端点生成图像。支持流式和非流式请求。 ```bash curl -X POST http://localhost:7860/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer your-api-key-1" \ -d '{ "model": "gemini-2.5-flash-image", "messages": [ { "role": "user", "content": "生成一只小猫" } ], "stream": false }' ``` ```bash curl -X POST http://localhost:7860/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer your-api-key-1" \ -d '{ "model": "gemini-2.5-flash-image", "messages": [ { "role": "user", "content": "生成一只小猫" } ], "stream": true }' ``` -------------------------------- ### Update to Latest Version Source: https://github.com/ibuhub/aistudiotoapi/blob/main/README.md Update your local deployment to the latest version by pulling changes and reinstalling dependencies. ```bash git pull npm install ``` -------------------------------- ### Check for New Version Source: https://context7.com/ibuhub/aistudiotoapi/llms.txt This endpoint checks if a new version of the system is available. Requires authentication. ```bash curl http://localhost:2048/api/version/check \ -H "Authorization: Bearer your-api-key" ``` -------------------------------- ### Gemini 原生 API 文本生成 Source: https://github.com/ibuhub/aistudiotoapi/blob/main/docs/zh/api-examples.md 使用 Gemini 原生 generateContent 端点。流式响应需在 URL 中添加 alt=sse 参数。 ```bash curl -X POST http://localhost:7860/v1beta/models/gemini-2.5-flash-lite:generateContent \ -H "Content-Type: application/json" \ -H "Authorization: Bearer your-api-key-1" \ -d '{ "contents": [ { "role": "user", "parts": [ { "text": "你好,最近怎么样?" } ] } ] }' ``` ```bash curl -X POST http://localhost:7860/v1beta/models/gemini-2.5-flash-lite:streamGenerateContent?alt=sse \ -H "Content-Type: application/json" \ -H "Authorization: Bearer your-api-key-1" \ -d '{ "contents": [ { "role": "user", "parts": [ { "text": "写一首关于秋天的诗" } ] } ] }' ``` -------------------------------- ### Responses API 调用 Source: https://github.com/ibuhub/aistudiotoapi/blob/main/docs/zh/api-examples.md 使用 v1/responses 端点进行交互,支持文本输入和结构化消息输入。 ```bash curl -X POST http://localhost:7860/v1/responses \ -H "Content-Type: application/json" \ -H "Authorization: Bearer your-api-key-1" \ -d '{ "model": "gemini-2.5-flash-lite", "input": "请用三句话总结函数式编程的核心思想。", "stream": false }' ``` ```bash curl -X POST http://localhost:7860/v1/responses \ -H "Content-Type: application/json" \ -H "Authorization: Bearer your-api-key-1" \ -d '{ "model": "gemini-2.5-flash-lite", "input": [ { "role": "user", "content": [ { "type": "input_text", "text": "写一首关于秋天的短诗。" } ] } ], "stream": true }' ``` -------------------------------- ### OpenAI 兼容 API 文本生成 Source: https://github.com/ibuhub/aistudiotoapi/blob/main/docs/zh/api-examples.md 使用 OpenAI 兼容的 chat/completions 端点进行文本生成。支持通过设置 stream 参数切换流式响应。 ```bash curl -X POST http://localhost:7860/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer your-api-key-1" \ -d '{ "model": "gemini-2.5-flash-lite", "messages": [ { "role": "user", "content": "你好,最近怎么样?" } ], "stream": false }' ``` ```bash curl -X POST http://localhost:7860/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer your-api-key-1" \ -d '{ "model": "gemini-2.5-flash-lite", "messages": [ { "role": "user", "content": "写一首关于秋天的诗" } ], "stream": true }' ``` -------------------------------- ### Switch to Specific Account Source: https://context7.com/ibuhub/aistudiotoapi/llms.txt Switch to a specific account by providing its index in the request body. Requires authentication and JSON content. ```bash curl -X PUT http://localhost:2048/api/accounts/current \ -H "Content-Type: application/json" \ -H "Authorization: Bearer your-api-key" \ -d '{"targetIndex": 2}' ``` -------------------------------- ### Batch Upload Authentication Files Source: https://context7.com/ibuhub/aistudiotoapi/llms.txt Upload multiple authentication files in a single request. Requires authentication and JSON content. ```bash curl -X POST http://localhost:2048/api/files/batch \ -H "Content-Type: application/json" \ -H "Authorization: Bearer your-api-key" \ -d '{ "files": [ {"cookies": [...], "localStorage": {...}}, {"cookies": [...], "localStorage": {...}} ] }' ``` -------------------------------- ### Batch Download Accounts Source: https://context7.com/ibuhub/aistudiotoapi/llms.txt Download authentication files for multiple accounts, packaged as a ZIP archive. Requires authentication and JSON content. ```bash curl -X POST http://localhost:2048/api/accounts/batch/download \ -H "Content-Type: application/json" \ -H "Authorization: Bearer your-api-key" \ -d '{"indices": [0, 1, 2]}' \ --output auth_backup.zip ``` -------------------------------- ### Run Docker Container from Built Image Source: https://github.com/ibuhub/aistudiotoapi/blob/main/README.md Run a Docker container using a locally built image. This is an alternative to pulling directly from a registry. ```bash docker run -d \ --name aistudio-to-api \ -p 7860:7860 \ -v /path/to/auth:/app/configs/auth \ -e API_KEYS=your-api-key-1,your-api-key-2 \ -e TZ=Asia/Shanghai \ --restart unless-stopped \ aistudio-to-api ``` -------------------------------- ### 配置内层 Nginx 代理 Source: https://github.com/ibuhub/aistudiotoapi/blob/main/docs/zh/nginx-setup.md 在多层代理架构中,内层网关应透传上游的 X-Real-IP 而非覆盖。 ```nginx # 内层 Nginx(内网网关)配置示例 location / { proxy_pass http://127.0.0.1:7860; # 关键:透传上游的 X-Real-IP,不要用 $remote_addr 覆盖 proxy_set_header X-Real-IP $http_x_real_ip; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # 其他必要的代理头 proxy_set_header Host $host; proxy_set_header X-Forwarded-Proto $scheme; # 超时设置 proxy_connect_timeout 600s; proxy_send_timeout 600s; proxy_read_timeout 600s; # 禁用缓冲区 proxy_buffering off; # WebSocket 支持(访问 VNC 时需要) proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; } ``` -------------------------------- ### Gemini 原生 API 图像生成 Source: https://github.com/ibuhub/aistudiotoapi/blob/main/docs/zh/api-examples.md 使用 gemini-2.5-flash-image 模型通过原生端点生成图像。 ```bash curl -X POST http://localhost:7860/v1beta/models/gemini-2.5-flash-image:generateContent \ -H "Content-Type: application/json" \ -H "Authorization: Bearer your-api-key-1" \ -d '{ "contents": [ { "role": "user", "parts": [ { "text": "生成一只小猫" } ] } ] }' ``` ```bash curl -X POST http://localhost:7860/v1beta/models/gemini-2.5-flash-image:streamGenerateContent?alt=sse \ -H "Content-Type: application/json" \ -H "Authorization: Bearer your-api-key-1" \ -d '{ "contents": [ { "role": "user", "parts": [ { "text": "生成一只小猫" } ] } ] }' ``` -------------------------------- ### Download Authentication File Source: https://context7.com/ibuhub/aistudiotoapi/llms.txt Download a specific authentication file by its filename. Requires authentication. ```bash curl http://localhost:2048/api/files/auth-0.json \ -H "Authorization: Bearer your-api-key" \ --output auth-0.json ``` -------------------------------- ### Switch Streaming Mode Source: https://context7.com/ibuhub/aistudiotoapi/llms.txt Toggle between 'real' and 'fake' streaming modes for responses. Requires authentication and JSON content. ```bash curl -X PUT http://localhost:2048/api/settings/streaming-mode \ -H "Content-Type: application/json" \ -H "Authorization: Bearer your-api-key" \ -d '{"mode": "real"}' ``` -------------------------------- ### List Available Models Source: https://context7.com/ibuhub/aistudiotoapi/llms.txt Retrieve a list of all models supported by the API. This endpoint is useful for discovering available model IDs. ```bash curl http://localhost:2048/v1/models \ -H "Authorization: Bearer your-api-key" ``` -------------------------------- ### POST /v1beta/models/gemini-2.5-flash-preview-tts:generateContent Source: https://github.com/ibuhub/aistudiotoapi/blob/main/docs/zh/api-examples.md Generates audio content from text input. Supports default voices, specific prebuilt voices, and multi-speaker configurations. ```APIDOC ## POST /v1beta/models/gemini-2.5-flash-preview-tts:generateContent ### Description Generates speech from text. The response returns base64 encoded audio in audio/L16;codec=pcm;rate=24000 format. ### Method POST ### Endpoint http://localhost:7860/v1beta/models/gemini-2.5-flash-preview-tts:generateContent ### Request Body - **contents** (array) - Required - The input text content. - **generationConfig** (object) - Required - Configuration including responseModalities set to ["AUDIO"] and optional speechConfig. ### Response #### Success Response (200) - **audio** (string) - Base64 encoded PCM audio data. ``` -------------------------------- ### List Models Source: https://github.com/ibuhub/aistudiotoapi/blob/main/README.md Retrieves a list of available models. ```APIDOC ## GET /v1/models ### Description Lists available models. ### Method GET ### Endpoint /v1/models ``` -------------------------------- ### Upload Authentication File Source: https://context7.com/ibuhub/aistudiotoapi/llms.txt Upload a new authentication file containing cookies and local storage data. Requires authentication and JSON content. ```bash curl -X POST http://localhost:2048/api/files \ -H "Content-Type: application/json" \ -H "Authorization: Bearer your-api-key" \ -d '{ "content": {"cookies": [...], "localStorage": {...}} }' ``` -------------------------------- ### 配置 Nginx 反向代理 Source: https://github.com/ibuhub/aistudiotoapi/blob/main/docs/zh/nginx-setup.md 定义反向代理规则,包括超时设置、流式响应支持及 WebSocket 转发。需将 server_name 替换为实际域名。 ```nginx server { listen 80; listen [::]:80; # IPv6 支持 server_name your-domain.com; # 替换为你的域名 # 如果使用 HTTPS,取消注释以下行并配置 SSL 证书 # listen 443 ssl http2; # listen [::]:443 ssl http2; # IPv6 HTTPS # ssl_certificate /path/to/your/certificate.crt; # ssl_certificate_key /path/to/your/private.key; # 客户端请求体大小的限制(0 = 不限制) client_max_body_size 0; location / { # 反向代理到 Docker 容器 proxy_pass http://127.0.0.1:7860; # X-Real-IP: 传递真实客户端 IP proxy_set_header X-Real-IP $remote_addr; # X-Forwarded-For: 包含完整的代理链 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # 其他必要的代理头 proxy_set_header Host $host; proxy_set_header X-Forwarded-Proto $scheme; # 超时设置(适配长时间运行的 AI 请求) proxy_connect_timeout 600s; proxy_send_timeout 600s; proxy_read_timeout 600s; # 禁用缓冲区以支持流式响应 proxy_buffering off; # WebSocket 支持(访问 VNC 时需要) proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; } } ``` -------------------------------- ### Set Log Display Count Source: https://context7.com/ibuhub/aistudiotoapi/llms.txt Configure the maximum number of log entries to display in the web console. Requires authentication and JSON content. ```bash curl -X PUT http://localhost:2048/api/settings/log-max-count \ -H "Content-Type: application/json" \ -H "Authorization: Bearer your-api-key" \ -d '{"count": 200}' ``` -------------------------------- ### Toggle Debug Mode Source: https://context7.com/ibuhub/aistudiotoapi/llms.txt Switch between DEBUG and INFO log levels for system output. Requires authentication. ```bash curl -X PUT http://localhost:2048/api/settings/debug-mode \ -H "Authorization: Bearer your-api-key" ``` -------------------------------- ### OpenAI Compatible Chat Completions Source: https://context7.com/ibuhub/aistudiotoapi/llms.txt This endpoint allows you to create chat completions using models compatible with the OpenAI Chat Completions API format. It supports standard parameters like model, messages, temperature, and max_tokens, as well as streaming responses and function calling. ```APIDOC ## POST /v1/chat/completions ### Description Creates a chat completion request, fully compatible with the OpenAI Chat Completions API format. Supports standard parameters, streaming, and function calling. ### Method POST ### Endpoint `/v1/chat/completions` ### Request Body - **model** (string) - Required - The model to use for chat completions (e.g., "gemini-2.5-flash"). - **messages** (array) - Required - A list of message objects representing the conversation history. - **role** (string) - Required - The role of the author of the message (e.g., "system", "user", "assistant"). - **content** (string) - Required - The content of the message. - **temperature** (number) - Optional - Controls randomness. Lower values make the output more focused and deterministic. - **max_tokens** (integer) - Optional - The maximum number of tokens to generate in the completion. - **stream** (boolean) - Optional - Whether to stream back partial message deltas as they are generated. - **tools** (array) - Optional - A list of tools the model may call. - **tool_choice** (string or object) - Optional - Controls how the tool is called. ### Request Example (Standard) ```bash { "model": "gemini-2.5-flash", "messages": [ {"role": "system", "content": "你是一个专业的AI助手"}, {"role": "user", "content": "请解释什么是机器学习"} ], "temperature": 0.7, "max_tokens": 2048, "stream": false } ``` ### Request Example (Streaming) ```bash { "model": "gemini-2.5-pro", "messages": [ {"role": "user", "content": "写一首关于春天的诗"} ], "stream": true } ``` ### Request Example (Function Calling) ```bash { "model": "gemini-2.5-flash", "messages": [ {"role": "user", "content": "北京今天的天气怎么样?"} ], "tools": [ { "type": "function", "function": { "name": "get_weather", "description": "获取指定城市的天气信息", "parameters": { "type": "object", "properties": { "city": { "type": "string", "description": "城市名称" } }, "required": ["city"] } } } ], "tool_choice": "auto" } ``` ### Response (Success) - **id** (string) - Unique identifier for the completion. - **object** (string) - Type of object returned (e.g., "chat.completion"). - **created** (integer) - Unix timestamp of creation. - **model** (string) - The model used for the completion. - **choices** (array) - A list of completion choices. - **index** (integer) - Index of the choice. - **message** (object) - The generated message. - **role** (string) - The role of the author (e.g., "assistant"). - **content** (string) - The content of the message. - **finish_reason** (string) - The reason the model stopped generating tokens. ### Response Example (Standard) ```json { "id": "chatcmpl-12345", "object": "chat.completion", "created": 1677652288, "model": "gemini-2.5-flash", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "机器学习是一种人工智能的分支..." }, "finish_reason": "stop" } ] } ``` ### Response Example (Streaming) ```json { "id": "chatcmpl-12345", "object": "chat.completion.chunk", "created": 1677652288, "model": "gemini-2.5-pro", "choices": [ { "index": 0, "delta": { "role": "assistant", "content": "春" }, "finish_reason": null } ] } ``` ``` -------------------------------- ### List Gemini Models (Native API Format) Source: https://github.com/ibuhub/aistudiotoapi/blob/main/README.md Retrieve a list of available Gemini models using the native Gemini API format. ```http GET /v1beta/models ``` -------------------------------- ### OpenAI Compatible Models List Source: https://context7.com/ibuhub/aistudiotoapi/llms.txt Retrieves a list of all available models that can be used with the chat completions endpoint. ```APIDOC ## GET /v1/models ### Description Retrieves a list of all available models compatible with the OpenAI API format. ### Method GET ### Endpoint `/v1/models` ### Parameters #### Query Parameters - **api-key** (string) - Required - Your API key for authentication. ### Request Example ```bash curl http://localhost:2048/v1/models \ -H "Authorization: Bearer your-api-key" ``` ### Response (Success) - **object** (string) - Type of object returned (e.g., "list"). - **data** (array) - A list of model objects. - **id** (string) - The unique identifier of the model. - **object** (string) - Type of object (e.g., "model"). - **created** (integer) - Unix timestamp of model creation. - **owned_by** (string) - The owner of the model (e.g., "google"). ### Response Example ```json { "object": "list", "data": [ { "id": "gemini-2.5-flash", "object": "model", "created": 1234567890, "owned_by": "google" }, { "id": "gemini-2.5-pro", "object": "model", "created": 1234567890, "owned_by": "google" } ] } ``` ``` -------------------------------- ### Toggle Force URL Context Source: https://context7.com/ibuhub/aistudiotoapi/llms.txt Enable or disable the forced URL context feature. Requires authentication. ```bash curl -X PUT http://localhost:2048/api/settings/force-url-context \ -H "Authorization: Bearer your-api-key" ``` -------------------------------- ### Google Gemini Native Generate Content Request Source: https://context7.com/ibuhub/aistudiotoapi/llms.txt Directly use the Google Gemini native API format for generating content. Include your API key in the URL query parameters. ```bash curl -X POST "http://localhost:2048/v1beta/models/gemini-2.5-flash:generateContent?key=your-api-key" \ -H "Content-Type: application/json" \ -d '{ "contents": [ { "parts": [ {"text": "用Python实现一个快速排序算法"} ] } ], "generationConfig": { "temperature": 0.7, "maxOutputTokens": 2048 } }' ``` -------------------------------- ### Translate OpenAI Chat Completions to Google Gemini Source: https://context7.com/ibuhub/aistudiotoapi/llms.txt Converts OpenAI Chat Completions format to Google Gemini format. ```APIDOC ## POST /api/translate/openai/chat/completions ### Description Converts OpenAI Chat Completions format to Google Gemini format. ### Method POST ### Endpoint /api/translate/openai/chat/completions ### Request Body - **model** (string) - Required - The model to use for translation. - **messages** (array) - Required - An array of message objects. - **role** (string) - Required - The role of the message author ('system', 'user', 'assistant'). - **content** (string) - Required - The content of the message. - **temperature** (number) - Optional - Controls randomness. Lower values make the output more deterministic. - **max_tokens** (integer) - Optional - The maximum number of tokens to generate. ### Request Example ```json { "model": "gemini-2.5-flash", "messages": [ { "role": "system", "content": "You are a helpful assistant" }, { "role": "user", "content": "Hello" } ], "temperature": 0.7, "max_tokens": 2048 } ``` ### Response #### Success Response (200) - **geminiRequest** (object) - The translated request in Google Gemini format. #### Response Example ```json { "model": "gemini-2.5-flash", "messages": [ { "role": "system", "content": "你是一个助手" }, { "role": "user", "content": "你好" } ], "temperature": 0.7, "max_tokens": 2048 } ``` ``` -------------------------------- ### Imagen 图像生成 Source: https://github.com/ibuhub/aistudiotoapi/blob/main/docs/zh/api-examples.md 使用 imagen-4.0-generate-001 模型通过 :predict 端点生成图像。可通过 sampleCount 参数控制生成数量。 ```bash curl -X POST http://localhost:7860/v1beta/models/imagen-4.0-generate-001:predict \ -H "Content-Type: application/json" \ -H "Authorization: Bearer your-api-key-1" \ -d '{ "instances": [ { "prompt": "机器人手持红色滑板" } ], "parameters": { "sampleCount": 1 } }' ``` ```bash curl -X POST http://localhost:7860/v1beta/models/imagen-4.0-generate-001:predict \ -H "Content-Type: application/json" \ -H "Authorization: Bearer your-api-key-1" \ -d '{ "instances": [ { "prompt": "夕阳下的未来城市,天空中有飞行汽车" } ], "parameters": { "sampleCount": 4 } }' ``` -------------------------------- ### POST /v1/responses Source: https://context7.com/ibuhub/aistudiotoapi/llms.txt Generates responses compatible with OpenAI's Response API format, supporting complex interaction patterns. ```APIDOC ## POST /v1/responses ### Description Generates responses compatible with OpenAI's Response API format, supporting complex interaction patterns. ### Method POST ### Endpoint /v1/responses ### Parameters #### Request Body - **model** (string) - Required - The AI model to use for generation. - **input** (string) - Required - The prompt or input for the AI model. - **reasoning** (object) - Optional - Configuration for reasoning, e.g., `{"effort": "high"}`. ### Request Example ```json { "model": "gemini-2.5-flash", "input": "解释什么是RESTful API" } ``` ### Request Example with Reasoning ```json { "model": "gemini-2.5-pro", "input": "设计一个电商系统的数据库架构", "reasoning": { "effort": "high" } } ``` ``` -------------------------------- ### Generate Content (Gemini Native API) Source: https://github.com/ibuhub/aistudiotoapi/blob/main/README.md Use this endpoint to generate content, images, and speech via the Gemini API. Specify the model name in the URL. ```http POST /v1beta/models/{model_name}:generateContent ``` -------------------------------- ### Chat Completions (OpenAI Compatible) Source: https://github.com/ibuhub/aistudiotoapi/blob/main/README.md Send chat completion requests using the OpenAI compatible API. Supports non-streaming, true streaming, and pseudo-streaming responses. Also supports image generation. ```http POST /v1/chat/completions ``` -------------------------------- ### Stream Generate Content (Gemini Native API) Source: https://github.com/ibuhub/aistudiotoapi/blob/main/README.md Enable streaming of content, images, and speech generation using the Gemini API. Supports true and pseudo-streaming. ```http POST /v1beta/models/{model_name}:streamGenerateContent ``` -------------------------------- ### Toggle Force Web Search Source: https://context7.com/ibuhub/aistudiotoapi/llms.txt Enable or disable the forced web search functionality. Requires authentication. ```bash curl -X PUT http://localhost:2048/api/settings/force-web-search \ -H "Authorization: Bearer your-api-key" ``` -------------------------------- ### OpenAI Chat Completions API Request Source: https://context7.com/ibuhub/aistudiotoapi/llms.txt Send a chat completion request using the OpenAI compatible endpoint. Ensure to replace 'your-api-key' with your actual API key. ```bash curl -X POST http://localhost:2048/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer your-api-key" \ -d '{ "model": "gemini-2.5-flash", "messages": [ {"role": "system", "content": "你是一个专业的AI助手"}, {"role": "user", "content": "请解释什么是机器学习"} ], "temperature": 0.7, "max_tokens": 2048, "stream": false }' ``` -------------------------------- ### OpenAI Chat Completions Streaming Request Source: https://context7.com/ibuhub/aistudiotoapi/llms.txt Initiate a streaming chat completion request. This is useful for real-time responses. Replace 'your-api-key' with your valid API key. ```bash curl -X POST http://localhost:2048/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer your-api-key" \ -d '{ "model": "gemini-2.5-pro", "messages": [ {"role": "user", "content": "写一首关于春天的诗"} ], "stream": true }' ``` -------------------------------- ### Settings Management Endpoints Source: https://context7.com/ibuhub/aistudiotoapi/llms.txt Endpoints for managing various system settings like streaming mode, thinking mode, web search, URL context, debug mode, and log display count. ```APIDOC ## PUT /api/settings/streaming-mode ### Description Switches between real streaming and fake streaming modes. ### Method PUT ### Endpoint /api/settings/streaming-mode ### Parameters #### Headers - **Content-Type** (string) - Required - `application/json` - **Authorization** (string) - Required - Bearer token for authentication. #### Request Body - **mode** (string) - Required - The streaming mode to set (`real` or `fake`). ### Request Example ```json { "mode": "real" } ``` ## PUT /api/settings/force-thinking ### Description Toggles the force thinking mode. ### Method PUT ### Endpoint /api/settings/force-thinking ### Parameters #### Headers - **Authorization** (string) - Required - Bearer token for authentication. ## PUT /api/settings/force-web-search ### Description Toggles the force web search feature. ### Method PUT ### Endpoint /api/settings/force-web-search ### Parameters #### Headers - **Authorization** (string) - Required - Bearer token for authentication. ## PUT /api/settings/force-url-context ### Description Toggles the force URL context feature. ### Method PUT ### Endpoint /api/settings/force-url-context ### Parameters #### Headers - **Authorization** (string) - Required - Bearer token for authentication. ## PUT /api/settings/debug-mode ### Description Switches between DEBUG and INFO log levels. ### Method PUT ### Endpoint /api/settings/debug-mode ### Parameters #### Headers - **Authorization** (string) - Required - Bearer token for authentication. ## PUT /api/settings/log-max-count ### Description Sets the maximum number of log entries to display in the web console. ### Method PUT ### Endpoint /api/settings/log-max-count ### Parameters #### Headers - **Content-Type** (string) - Required - `application/json` - **Authorization** (string) - Required - Bearer token for authentication. #### Request Body - **count** (integer) - Required - The maximum number of logs to display. ### Request Example ```json { "count": 200 } ``` ``` -------------------------------- ### Docker Compose Configuration Source: https://github.com/ibuhub/aistudiotoapi/blob/main/README.md Define the Docker service configuration in a docker-compose.yml file for easier deployment and management. This includes port mapping, volume mounting, and environment variables. ```yaml name: aistudio-to-api services: app: image: ghcr.io/ibuhub/aistudio-to-api:latest container_name: aistudio-to-api ports: # API 服务器端口(如果使用反向代理,强烈建议改成 127.0.0.1:7860) - 7860:7860 restart: unless-stopped volumes: # 挂载包含认证文件的目录 - ./auth:/app/configs/auth environment: # 用于身份验证的 API 密钥列表(使用逗号分隔) API_KEYS: your-api-key-1,your-api-key-2 # 时区设置(可选,默认使用系统时区) TZ: Asia/Shanghai ``` -------------------------------- ### Interact with Anthropic-compatible API Source: https://github.com/ibuhub/aistudiotoapi/blob/main/docs/zh/api-examples.md Send messages to the model using the Anthropic-compatible endpoint, supporting both standard and streaming responses. ```bash curl -X POST http://localhost:7860/v1/messages \ -H "Content-Type: application/json" \ -H "x-api-key: your-api-key-1" \ -H "anthropic-version: 2023-06-01" \ -d '{ "model": "gemini-2.5-flash-lite", "max_tokens": 1024, "messages": [ { "role": "user", "content": "你好,最近怎么样?" } ], "stream": false }' ``` ```bash curl -X POST http://localhost:7860/v1/messages \ -H "Content-Type: application/json" \ -H "x-api-key: your-api-key-1" \ -H "anthropic-version: 2023-06-01" \ -d '{ "model": "gemini-2.5-flash-lite", "max_tokens": 1024, "messages": [ { "role": "user", "content": "写一首关于秋天的诗" } ], "stream": true }' ```