### Untitled No description -------------------------------- ### Run Next.js Development Server (Bash) Source: https://github.com/djhdj1/veloera/blob/main/web_v2/README.md Commands to start the Next.js development server using different package managers. This allows for live-reloading and immediate feedback during development. ```bash npm run dev # or yarn dev # or pnpm dev # or bun dev ``` -------------------------------- ### Get Pricing Information API (Go) Source: https://context7.com/djhdj1/veloera/llms.txt Retrieves model pricing and group ratios from the server. It uses the gin framework and returns pricing data, group multipliers, and usable groups. Accessible via GET /api/pricing. ```go // From controller/pricing.go func GetPricing(c *gin.Context) { pricing := model.GetPricing() groupRatio := setting.GetGroupRatioCopy() usableGroup := setting.GetUserUsableGroups(group) c.JSON(200, gin.H{ "success": true, "data": pricingWithPrefixes, "group_ratio": groupRatio, "usable_group": usableGroup, }) } ``` -------------------------------- ### Untitled No description -------------------------------- ### Docker Compose Deployment and Updates Source: https://github.com/djhdj1/veloera/blob/main/new-api-stuffs/README.en.md This snippet demonstrates how to deploy the project using Docker Compose and how to update the deployed version. It involves cloning the repository, editing the docker-compose.yml file, and then starting or updating the services. ```shell # Clone project git clone https://github.com/Calcium-Ion/new-api.git cd new-api # Edit docker-compose.yml as needed # nano docker-compose.yml # vim docker-compose.yml # Start docker-compose up -d # Update Version docker-compose pull docker-compose up -d ``` -------------------------------- ### Create API Token API Request (Bash) Source: https://context7.com/djhdj1/veloera/llms.txt Demonstrates creating an API token via a GET request to the user token endpoint, typically authenticated with a session cookie. The response contains the newly generated API key. ```bash curl -X GET http://localhost:3000/api/user/token \ -H "Cookie: session=xxxxx" ``` -------------------------------- ### Token Management API Response Format Source: https://github.com/djhdj1/veloera/blob/main/web_v2/web_features.md Example JSON response for the /api/token endpoint, listing user tokens with details like ID, name, key, status, and quota information. ```bash # API Calls # GET /api/token - Retrieves all tokens for the current user # DELETE /api/token/:id - Deletes a token ``` ```json // /api/token response { "success": true, "message": "", "data": [ { "id": 1, "name": "Token 1", "key": "sk-abcdef123456", "status": 1, "created_time": 1672531200, "accessed_time": 1672617600, "expired_time": 1704067200, "remain_quota": 10000, "unlimited_quota": false } ] } ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### User API Response Format Source: https://github.com/djhdj1/veloera/blob/main/web_v2/web_features.md Example JSON response from the /api/user/self endpoint, detailing user information such as ID, username, email, role, and quota. ```json // /api/user/self response { "success": true, "message": "", "data": { "id": 1, "username": "user", "display_name": "User", "email": "user@example.com", "role": 1, "status": 1, "quota": 100000, "used_quota": 5000, "request_count": 100, "created_at": "2023-01-01T00:00:00Z" } } ``` -------------------------------- ### API Token Response Example Source: https://github.com/djhdj1/veloera/blob/main/web_v2/web_features.md This JSON object represents a successful response when retrieving information about an API token. It includes details such as the token's ID, name, key, status, creation and access times, quota information, and associated configurations like model limits and allowed IPs. ```json // GET /api/token/:id response { "success": true, "message": "", "data": { "id": 1, "name": "Token Name", "key": "sk-abcdef123456", "status": 1, "created_time": 1672531200, "accessed_time": 1672617600, "expired_time": 1704067200, "remain_quota": 10000, "unlimited_quota": false, "model_limits_enabled": true, "model_limits": "gpt-3.5-turbo,gpt-4", "allow_ips": "192.168.1.1,10.0.0.1", "group": "group1" } } ``` -------------------------------- ### Get Dashboard Statistics API (Bash) Source: https://context7.com/djhdj1/veloera/llms.txt Retrieves quota usage statistics for dashboard display. Requires start and end timestamps as query parameters. Accessible via GET /api/data. ```bash curl -X GET "http://localhost:3000/api/data?start_timestamp=1698796800&end_timestamp=1699999999" \ -H "Cookie: session=xxxxx" # Response: # { # "success": true, # "data": [ # { # "date": "2024-01-15", # "model_name": "gpt-4", # "quota": 125000, # "request_count": 450 # }, # { # "date": "2024-01-15", # "model_name": "gpt-3.5-turbo", # "quota": 35000, # "request_count": 1250 # } # ] # } ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Get Usage Logs using cURL Source: https://context7.com/djhdj1/veloera/llms.txt Retrieves system usage logs with various filtering options. This GET request requires a session cookie and allows filtering by page, page size, type, timestamp range, model name, channel ID, and group. The response contains a list of log items and pagination details. ```bash curl -X GET "http://localhost:3000/api/log?p=1&page_size=50&type=2&start_timestamp=1699000000&end_timestamp=1699999999&model_name=gpt-4&channel=1&group=default" \ -H "Cookie: session=xxxxx" ``` -------------------------------- ### Clone and Deploy New API with Docker Compose Source: https://github.com/djhdj1/veloera/blob/main/README.md This snippet shows the commands to clone the New API project repository and then deploy it using Docker Compose. It's a recommended method for deployment. ```shell git clone https://github.com/Calcium-Ion/new-api.git cd new-api # Edit docker-compose.yml as needed docker-compose up -d ``` -------------------------------- ### Direct Docker Image Deployment (SQLite and MySQL) Source: https://github.com/djhdj1/veloera/blob/main/new-api-stuffs/README.en.md Instructions for deploying the application directly using a Docker image. It covers both SQLite and MySQL database configurations, specifying necessary environment variables and volume mounts. ```shell # SQLite deployment: docker run --name new-api -d --restart always -p 3000:3000 -e TZ=Asia/Shanghai -v /home/ubuntu/data/new-api:/data calciumion/new-api:latest # MySQL deployment (add -e SQL_DSN="root:123456@tcp(localhost:3306)/oneapi"), modify database connection parameters as needed # Example: docker run --name new-api -d --restart always -p 3000:3000 -e SQL_DSN="root:123456@tcp(localhost:3306)/oneapi" -e TZ=Asia/Shanghai -v /home/ubuntu/data/new-api:/data calciumion/new-api:latest ``` -------------------------------- ### GET /api/pricing Source: https://context7.com/djhdj1/veloera/llms.txt Retrieves model pricing and group ratios. ```APIDOC ## GET /api/pricing ### Description Retrieve model pricing and group ratios. ### Method GET ### Endpoint /api/pricing ### Parameters #### Query Parameters - **group** (string) - Optional - The group to filter pricing information by. ### Response #### Success Response (200) - **success** (boolean) - Indicates if the request was successful. - **data** (object) - Contains pricing information for models. - **group_ratio** (object) - Contains group multipliers. - **usable_group** (array) - Lists available groups for the user. #### Response Example ```json { "success": true, "data": { ... }, "group_ratio": { ... }, "usable_group": [ ... ] } ``` ``` -------------------------------- ### Initialize Databases with Auto-Migration (Go) Source: https://context7.com/djhdj1/veloera/llms.txt Initializes database connections supporting SQLite, MySQL, and PostgreSQL. It automatically migrates all defined models (User, Token, Channel, etc.) on startup. Dependencies include the 'os' package and the 'gorm' ORM with specific database drivers. ```go // From model/setup.go and main.go func InitDB() error { var err error var dsn string if os.Getenv("SQL_DSN") != "" { dsn = os.Getenv("SQL_DSN") DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{}) } else if os.Getenv("POSTGRES_DSN") != "" { dsn = os.Getenv("POSTGRES_DSN") DB, err = gorm.Open(postgres.Open(dsn), &gorm.Config{}) } else { // Default to SQLite db := "./veloera.db" DB, err = gorm.Open(sqlite.Open(db), &gorm.Config{}) } if err != nil { return err } // Auto-migrate all models DB.AutoMigrate(&User{}, &Token{}, &Channel{}, &Redemption{}, &Ability{}, &Log{}) return nil } // Supported databases: // - SQLite (default, embedded) // - MySQL (version >= 5.7.8) // - PostgreSQL (version >= 9.6) // - Automatic schema migration on startup // - Connection pooling and health checks ``` -------------------------------- ### GET /task/list-by-condition Source: https://github.com/djhdj1/veloera/blob/main/new-api-stuffs/Midjourney.md Retrieves a list of tasks based on specified conditions. ```APIDOC ## GET /task/list-by-condition ### Description Retrieves a list of tasks based on specified conditions. ### Method GET ### Endpoint /task/list-by-condition ### Parameters #### Query Parameters - **condition** (string) - Optional - A string representing the conditions to filter tasks. ### Response #### Success Response (200) - **code** (integer) - The status code of the operation. - **description** (string) - A message describing the result of the operation. - **result** (array) - An array of task objects matching the conditions. #### Response Example ```json { "code": 200, "description": "success", "result": [ { "taskId": "mj-task-12345", "prompt": "a futuristic cityscape at sunset", "status": "completed" }, { "taskId": "mj-task-67890", "prompt": "a cat in a hat", "status": "failed" } ] } ``` ``` -------------------------------- ### Untitled No description -------------------------------- ### GET /api/data Source: https://context7.com/djhdj1/veloera/llms.txt Retrieves quota usage statistics for dashboard display. ```APIDOC ## GET /api/data ### Description Retrieve quota usage statistics for dashboard display. ### Method GET ### Endpoint /api/data ### Parameters #### Query Parameters - **start_timestamp** (integer) - Required - The start of the time range (Unix timestamp). - **end_timestamp** (integer) - Required - The end of the time range (Unix timestamp). ### Response #### Success Response (200) - **success** (boolean) - Indicates if the request was successful. - **data** (array) - An array of objects, each containing date, model name, quota usage, and request count. #### Response Example ```json { "success": true, "data": [ { "date": "2024-01-15", "model_name": "gpt-4", "quota": 125000, "request_count": 450 }, { "date": "2024-01-15", "model_name": "gpt-3.5-turbo", "quota": 35000, "request_count": 1250 } ] } ``` ``` -------------------------------- ### Get Current User Profile API Source: https://context7.com/djhdj1/veloera/llms.txt Retrieves the profile information for the currently authenticated user. ```APIDOC ## GET /api/user/self ### Description Retrieve current authenticated user information. ### Method GET ### Endpoint /api/user/self ### Parameters #### Headers - **Authorization** (string) - Optional - Bearer token for authentication (e.g., `Bearer sk-xxxxx`). - **Cookie** (string) - Optional - Session cookie for authentication. ### Response #### Success Response (200) - **success** (boolean) - Indicates if the request was successful. - **data** (object) - User profile details. - **id** (integer) - User ID. - **username** (string) - Username. - **email** (string) - User's email address. - **quota** (integer) - User's allocated quota. - **used_quota** (integer) - User's used quota. - **group** (string) - User's assigned group. - [Other user-related fields] #### Response Example { "success": true, "data": { "id": 1, "username": "admin", "display_name": "Administrator", "role": 100, "status": 1, "email": "admin@example.com", "quota": 1000000, "used_quota": 50000, "group": "default" } } ``` -------------------------------- ### Untitled No description -------------------------------- ### GET /mj/image/{id} Source: https://github.com/djhdj1/veloera/blob/main/new-api-stuffs/Midjourney.md Retrieves an image by its ID. Requires server address to be configured in system settings. ```APIDOC ## GET /mj/image/{id} ### Description Retrieves an image by its ID. Please ensure the server address is configured in system settings. ### Method GET ### Endpoint /mj/image/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the image to retrieve. ### Response #### Success Response (200) - The response will be the image data (e.g., binary image file). #### Response Example [Image Binary Data] ``` -------------------------------- ### Run New API with Docker (MySQL) Source: https://github.com/djhdj1/veloera/blob/main/README.md This command shows how to run the New API using a Docker container with MySQL as the database. It includes environment variables for database connection and timezone. ```shell docker run --name new-api -d --restart always -p 3000:3000 -e SQL_DSN="root:123456@tcp(localhost:3306)/oneapi" -e TZ=Asia/Shanghai -v /home/ubuntu/data/new-api:/data calciumion/new-api:latest ``` -------------------------------- ### GET /mj/task/{id}/fetch Source: https://github.com/djhdj1/veloera/blob/main/new-api-stuffs/Midjourney.md Fetches the details of a task by its ID. The image URLs returned are proxied through One API. ```APIDOC ## GET /mj/task/{id}/fetch ### Description Fetches the details of a task by its ID. The image URLs returned are proxied through One API. ### Method GET ### Endpoint /mj/task/{id}/fetch ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the task to fetch. ### Response #### Success Response (200) - **code** (integer) - The status code of the operation. - **description** (string) - A message describing the result of the operation. - **result** (object) - The result of the operation, containing task details, including image URLs. - **status** (string) - The status of the task (e.g., "completed", "in_progress"). - **imageUrl** (string) - The proxied URL of the generated image. #### Response Example ```json { "code": 200, "description": "success", "result": { "status": "completed", "imageUrl": "http://your-proxy-url.com/images/generated_image.png" } } ``` ``` -------------------------------- ### Run New API with Docker (SQLite) Source: https://github.com/djhdj1/veloera/blob/main/README.md This command demonstrates how to run the New API using a Docker container with SQLite as the database. It maps port 3000 and mounts a volume for data persistence. ```shell docker run --name new-api -d --restart always -p 3000:3000 -e TZ=Asia/Shanghai -v /home/ubuntu/data/new-api:/data calciumion/new-api:latest ``` -------------------------------- ### Untitled No description -------------------------------- ### Get Usage Logs Source: https://context7.com/djhdj1/veloera/llms.txt Retrieve system usage logs with various filtering options including date range, model, channel, and group. ```APIDOC ## GET /api/log ### Description Retrieve system usage logs with filtering options. ### Method GET ### Endpoint /api/log ### Parameters #### Query Parameters - **p** (integer) - Optional - Page number for pagination. Defaults to 0. - **page_size** (integer) - Optional - Number of items per page. Defaults to 20. - **type** (integer) - Optional - Filter by log type. - **start_timestamp** (integer) - Optional - Unix timestamp for the start of the log retrieval period. - **end_timestamp** (integer) - Optional - Unix timestamp for the end of the log retrieval period. - **model_name** (string) - Optional - Filter logs by model name. - **channel** (integer) - Optional - Filter logs by channel ID. - **group** (string) - Optional - Filter logs by group name. #### Request Body None ### Request Example ```bash curl -X GET "http://localhost:3000/api/log?p=1&page_size=50&type=2&start_timestamp=1699000000&end_timestamp=1699999999&model_name=gpt-4&channel=1&group=default" \ -H "Cookie: session=xxxxx" ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the request was successful. - **message** (string) - Any relevant message. - **data** (object) - Log data. - **items** (array) - Array of log entries. - **id** (integer) - Unique identifier for the log entry. - **created_at** (integer) - Unix timestamp of log creation. - **user_id** (integer) - User ID associated with the log. - **username** (string) - Username. - **token_name** (string) - Name of the token used. - **model_name** (string) - Model name used. - **type** (integer) - Type of the log entry. - **channel_id** (integer) - ID of the channel used. - **channel_name** (string) - Name of the channel used. - **prompt_tokens** (integer) - Number of prompt tokens. - **completion_tokens** (integer) - Number of completion tokens. - **quota** (integer) - Quota consumed. - **content** (string) - Content of the log entry. - **total** (integer) - Total number of log entries available. - **page** (integer) - Current page number. - **page_size** (integer) - Number of items per page. #### Response Example ```json { "success": true, "message": "", "data": { "items": [ { "id": 12345, "created_at": 1699555555, "user_id": 5, "username": "user123", "token_name": "Production API Key", "model_name": "gpt-4", "type": 2, "channel_id": 1, "channel_name": "OpenAI Primary", "prompt_tokens": 125, "completion_tokens": 87, "quota": 4240, "content": "User question about AI" } ], "total": 1523, "page": 1, "page_size": 50 } } ``` ``` -------------------------------- ### Untitled No description -------------------------------- ### Update Channel Balance using cURL Source: https://context7.com/djhdj1/veloera/llms.txt Fetches and updates the balance for a specific channel. This GET request requires a session cookie and the channel ID. The response includes a success status, a message, and the updated balance. ```bash curl -X GET http://localhost:3000/api/channel/update_balance/25 \ -H "Cookie: session=xxxxx" ``` -------------------------------- ### Untitled No description -------------------------------- ### Test Channel using cURL Source: https://context7.com/djhdj1/veloera/llms.txt Tests the connectivity and functionality of a specific channel identified by its ID. This GET request requires a session cookie. The response indicates whether the test was successful and may include a duration or an error message. ```bash curl -X GET http://localhost:3000/api/channel/test/25 \ -H "Cookie: session=xxxxx" ``` -------------------------------- ### Untitled No description -------------------------------- ### Top Up API Source: https://github.com/djhdj1/veloera/blob/main/web_v2/web_features.md Endpoints for initiating top-ups, processing payments, and handling payment notifications. ```APIDOC ## POST /api/user/topup ### Description Initiates a top-up request by specifying the amount. ### Method POST ### Endpoint /api/user/topup ### Parameters #### Request Body - **amount** (integer) - Required - The amount to top up. ### Request Example ```json { "amount": 100 } ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the operation was successful. - **message** (string) - A message related to the operation. - **data** (object) - Contains payment details. - **payment_url** (string) - The URL to process the payment. #### Response Example ```json { "success": true, "message": "", "data": { "payment_url": "https://payment.example.com/pay" } } ``` ## POST /api/user/pay ### Description Processes the payment for a top-up. This endpoint is typically called after the user is redirected from the payment URL. ### Method POST ### Endpoint /api/user/pay ### Parameters (Note: Specific parameters for this endpoint are not detailed in the provided text, but would typically include payment confirmation details.) ### Response (Note: Specific response details for this endpoint are not detailed in the provided text.) ## GET /api/user/epay/notify ### Description Payment notification callback endpoint for the payment gateway. ### Method GET ### Endpoint /api/user/epay/notify ### Parameters (Note: Specific parameters for this endpoint are not detailed in the provided text, but would typically include payment status and transaction details.) ### Response (Note: Specific response details for this endpoint are not detailed in the provided text.) ``` -------------------------------- ### Rerank API Response Example (JSON) Source: https://github.com/djhdj1/veloera/blob/main/new-api-stuffs/Rerank.md This JSON object illustrates a successful response from the Rerank API. It contains a list of results, where each result includes the reranked document, its original index, and a relevance score. The 'usage' field provides token consumption details for the request. ```json { "results": [ { "document": { "text": "Washington, D.C. (also known as simply Washington or D.C., and officially as the District of Columbia) is the capital of the United States. It is a federal district." }, "index": 2, "relevance_score": 0.9999702 }, { "document": { "text": "Carson City is the capital city of the American state of Nevada." }, "index": 0, "relevance_score": 0.67800725 }, { "document": { "text": "Capitalization or capitalisation in English grammar is the use of a capital letter at the start of a word. English usage varies from capitalization in other languages." }, "index": 3, "relevance_score": 0.02800752 } ], "usage": { "prompt_tokens": 158, "completion_tokens": 0, "total_tokens": 158 } } ``` -------------------------------- ### Rerank API Request Example (JSON) Source: https://github.com/djhdj1/veloera/blob/main/new-api-stuffs/Rerank.md This JSON object represents a typical request to the Rerank API. It includes the model to use, the query, the number of top results to return, and a list of documents to be reranked. The API is designed to reorder these documents based on their relevance to the query. ```json { "model": "jina-reranker-v2-base-multilingual", "query": "What is the capital of the United States?", "top_n": 3, "documents": [ "Carson City is the capital city of the American state of Nevada.", "The Commonwealth of the Northern Mariana Islands is a group of islands in the Pacific Ocean. Its capital is Saipan.", "Washington, D.C. (also known as simply Washington or D.C., and officially as the District of Columbia) is the capital of the United States. It is a federal district.", "Capitalization or capitalisation in English grammar is the use of a capital letter at the start of a word. English usage varies from capitalization in other languages.", "Capital punishment (the death penalty) has existed in the United States since beforethe United States was a country. As of 2017, capital punishment is legal in 30 of the 50 states." ] } ```