|
| 1 | +syntax = "proto3"; |
| 2 | + |
| 3 | +package erda.apps.aiproxy.usage; |
| 4 | +option go_package = "github.com/erda-project/erda-proto-go/apps/aiproxy/usage/token/pb"; |
| 5 | + |
| 6 | +import "google/api/annotations.proto"; |
| 7 | +import "apps/aiproxy/metadata/metadata.proto"; |
| 8 | +import "google/protobuf/timestamp.proto"; |
| 9 | +import "github.com/envoyproxy/protoc-gen-validate/validate/validate.proto"; |
| 10 | +import "common/http.proto"; |
| 11 | +import "common/openapi.proto"; |
| 12 | + |
| 13 | +service TokenUsageService { |
| 14 | + rpc Create(TokenUsageCreateRequest) returns (TokenUsage) { |
| 15 | + option(google.api.http) = { |
| 16 | + post: "/api/ai-proxy/usages/token-usage" |
| 17 | + }; |
| 18 | + option (erda.common.openapi) = { |
| 19 | + private: true |
| 20 | + }; |
| 21 | + } |
| 22 | + |
| 23 | + rpc Paging(TokenUsagePagingRequest) returns (TokenUsagePagingResponse) { |
| 24 | + option(google.api.http) = { |
| 25 | + get: "/api/ai-proxy/usages/token-usage" |
| 26 | + }; |
| 27 | + } |
| 28 | + |
| 29 | + rpc Aggregate(TokenUsagePagingRequest) returns (TokenUsageAggregateResponse) { |
| 30 | + option(google.api.http) = { |
| 31 | + get: "/api/ai-proxy/usages/token-usage/aggregate" |
| 32 | + }; |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +message TokenUsage { |
| 37 | + uint64 id = 1; |
| 38 | + |
| 39 | + // request correlation |
| 40 | + string callId = 2 [(validate.rules).string = {min_len: 1, max_len: 64}]; |
| 41 | + string xRequestId = 3 [(validate.rules).string = {ignore_empty: true, min_len: 1, max_len: 64}]; |
| 42 | + |
| 43 | + // attribution |
| 44 | + string clientId = 4 [(validate.rules).string = {len: 36}]; |
| 45 | + string clientTokenId = 5 [(validate.rules).string = {ignore_empty: true, len: 36}]; |
| 46 | + string providerId = 6 [(validate.rules).string = {len: 36}]; |
| 47 | + string modelId = 7 [(validate.rules).string = {len: 36}]; |
| 48 | + |
| 49 | + google.protobuf.Timestamp createdAt = 8; // http request begin time |
| 50 | + google.protobuf.Timestamp updatedAt = 9; |
| 51 | + |
| 52 | + // usage |
| 53 | + uint64 inputTokens = 10; |
| 54 | + uint64 outputTokens = 11; |
| 55 | + uint64 totalTokens = 12; |
| 56 | + string usageDetails = 13; |
| 57 | + bool isEstimated = 14; |
| 58 | + |
| 59 | + metadata.Metadata metadata = 15; |
| 60 | +} |
| 61 | + |
| 62 | +message TokenUsageCreateRequest { |
| 63 | + // request correlation |
| 64 | + string callId = 1 [(validate.rules).string = {min_len: 1, max_len: 64}]; |
| 65 | + string xRequestId = 2 [(validate.rules).string = {min_len: 1, max_len: 64}]; |
| 66 | + |
| 67 | + // attribution |
| 68 | + string clientId = 3 [(validate.rules).string = {len: 36}]; |
| 69 | + string clientTokenId = 4 [(validate.rules).string = {ignore_empty: true, len: 36}]; |
| 70 | + string providerId = 5 [(validate.rules).string = {len: 36}]; |
| 71 | + string modelId = 6 [(validate.rules).string = {len: 36}]; |
| 72 | + |
| 73 | + google.protobuf.Timestamp createdAt = 7; |
| 74 | + |
| 75 | + // usage |
| 76 | + uint64 inputTokens = 8 [(validate.rules).uint64 = {gte: 0}]; |
| 77 | + uint64 outputTokens = 9 [(validate.rules).uint64 = {gte: 0}]; |
| 78 | + uint64 totalTokens = 10 [(validate.rules).uint64 = {gte: 0}]; |
| 79 | + string usageDetails = 11; |
| 80 | + bool isEstimated = 12; |
| 81 | + |
| 82 | + metadata.Metadata metadata = 13; |
| 83 | + |
| 84 | +} |
| 85 | + |
| 86 | +message TokenUsagePagingRequest { |
| 87 | + // paging |
| 88 | + int64 pageNum = 1 [(validate.rules).int64 = {ignore_empty: true, gte: 1}]; |
| 89 | + int64 pageSize = 2 [(validate.rules).int64 = {ignore_empty: true, gte: 1, lte: 1000}]; |
| 90 | + |
| 91 | + // request correlation |
| 92 | + string callId = 3 [(validate.rules).string = {ignore_empty: true, min_len: 1, max_len: 64}]; |
| 93 | + string xRequestId = 4 [(validate.rules).string = {min_len: 0, max_len: 64}]; |
| 94 | + |
| 95 | + // attribution |
| 96 | + string clientId = 5 [(validate.rules).string = {ignore_empty: true, len: 36}]; |
| 97 | + string clientTokenId = 6 [(validate.rules).string = {ignore_empty: true, len: 36}]; |
| 98 | + string providerId = 7 [(validate.rules).string = {ignore_empty: true, len: 36}]; |
| 99 | + string modelId = 8 [(validate.rules).string = {ignore_empty: true, len: 36}]; |
| 100 | + |
| 101 | + repeated uint64 ids = 9; |
| 102 | + optional bool isEstimated = 10; |
| 103 | + |
| 104 | + // time range |
| 105 | + // unix milliseconds, used for http query parsing convenience |
| 106 | + uint64 timeRangeAfterMs = 11 [(validate.rules).uint64 = {ignore_empty: true, gte: 0}]; |
| 107 | + uint64 timeRangeBeforeMs = 12 [(validate.rules).uint64 = {ignore_empty: true, gte: 0}]; |
| 108 | +} |
| 109 | + |
| 110 | +message TokenUsagePagingResponse { |
| 111 | + uint64 total = 1; |
| 112 | + repeated TokenUsage list = 2; |
| 113 | +} |
| 114 | + |
| 115 | +message TokenUsageAggregateResponse { |
| 116 | + double totalCost = 1; |
| 117 | + string currency = 2; |
| 118 | + uint64 totalInputTokens = 3; |
| 119 | + uint64 totalOutputTokens = 4; |
| 120 | + uint64 totalTokens = 5; |
| 121 | + uint64 recordCount = 6; |
| 122 | + repeated TokenUsageDetail details = 7; |
| 123 | +} |
| 124 | + |
| 125 | +message TokenUsageDetail { |
| 126 | + double cost = 1; |
| 127 | + string currency = 2; |
| 128 | + // usage |
| 129 | + uint64 recordId = 3; |
| 130 | + uint64 inputTokens = 4; |
| 131 | + uint64 outputTokens = 5; |
| 132 | + uint64 totalTokens = 6; |
| 133 | + string modelId = 7 [(validate.rules).string = {len: 36}]; |
| 134 | +} |
0 commit comments