|
| 1 | +import "@typespec/json-schema"; |
| 2 | +import "../shared/index.tsp"; |
| 3 | + |
| 4 | +namespace Meters; |
| 5 | + |
| 6 | +/** |
| 7 | + * The granularity of the time grouping. |
| 8 | + * Time durations are specified in ISO 8601 format. |
| 9 | + */ |
| 10 | +@friendlyName("MeterQueryGranularity") |
| 11 | +union MeterQueryGranularity { |
| 12 | + /** |
| 13 | + * 1 minute time buckets. |
| 14 | + */ |
| 15 | + @summary("1 minute") |
| 16 | + Minute: "PT1M", |
| 17 | + |
| 18 | + /** |
| 19 | + * 1 hour time buckets. |
| 20 | + */ |
| 21 | + @summary("1 hour") |
| 22 | + Hour: "PT1H", |
| 23 | + |
| 24 | + /** |
| 25 | + * 1 day time buckets. |
| 26 | + */ |
| 27 | + @summary("1 day") |
| 28 | + Day: "P1D", |
| 29 | + |
| 30 | + /** |
| 31 | + * 1 month time buckets. |
| 32 | + */ |
| 33 | + @summary("1 month") |
| 34 | + Month: "P1M", |
| 35 | +} |
| 36 | + |
| 37 | +/** |
| 38 | + * Filters to apply to a meter query. |
| 39 | + */ |
| 40 | +@friendlyName("MeterQueryFilters") |
| 41 | +model MeterQueryFilters { |
| 42 | + /** |
| 43 | + * Filters to apply to the subject key of the query. |
| 44 | + * Only equals ("eq", "in") comparisons are supported. |
| 45 | + */ |
| 46 | + subject_key?: Shared.QueryFilterString; |
| 47 | + |
| 48 | + /** |
| 49 | + * Filters to apply to the customer ID of the query. |
| 50 | + * Only equals ("eq", "in") comparisons are supported. |
| 51 | + */ |
| 52 | + customer_id?: Shared.QueryFilterString; |
| 53 | + |
| 54 | + /** |
| 55 | + * Filters to apply to the dimensions of the query. |
| 56 | + */ |
| 57 | + @JsonSchema.maxProperties(10) |
| 58 | + dimensions?: Shared.QueryFilterStringMap; |
| 59 | +} |
| 60 | + |
| 61 | +/** |
| 62 | + * A meter query request. |
| 63 | + */ |
| 64 | +#suppress "@openmeter/api-spec/repeated-prefix-grouping" "keep the request flat" |
| 65 | +@friendlyName("MeterQueryRequest") |
| 66 | +@example(#{ |
| 67 | + from: Shared.DateTime.fromISO("2023-01-01T00:00:00Z"), |
| 68 | + to: Shared.DateTime.fromISO("2023-01-02T00:00:00Z"), |
| 69 | + granularity: MeterQueryGranularity.Day, |
| 70 | + time_zone: "UTC", |
| 71 | +}) |
| 72 | +model MeterQueryRequest { |
| 73 | + /** |
| 74 | + * The start of the period the usage is queried from. |
| 75 | + */ |
| 76 | + from?: Shared.DateTime; |
| 77 | + |
| 78 | + /** |
| 79 | + * The end of the period the usage is queried to. |
| 80 | + */ |
| 81 | + to?: Shared.DateTime; |
| 82 | + |
| 83 | + /** |
| 84 | + * The size of the time buckets to group the usage into. |
| 85 | + * If not specified, the usage is aggregated over the entire period. |
| 86 | + */ |
| 87 | + granularity?: MeterQueryGranularity; |
| 88 | + |
| 89 | + /** |
| 90 | + * The value is the name of the time zone as defined in the IANA Time Zone Database (http://www.iana.org/time-zones). |
| 91 | + * The time zone is used to determine the start and end of the time buckets. |
| 92 | + * If not specified, the UTC timezone will be used. |
| 93 | + */ |
| 94 | + time_zone?: string = "UTC"; |
| 95 | + |
| 96 | + /** |
| 97 | + * The dimensions to group the results by. |
| 98 | + */ |
| 99 | + @example(#["model", "type"]) |
| 100 | + @maxItems(100) |
| 101 | + group_by_dimensions?: string[]; |
| 102 | + |
| 103 | + /** |
| 104 | + * Filters to apply to the query. |
| 105 | + */ |
| 106 | + filters?: MeterQueryFilters; |
| 107 | +} |
| 108 | + |
| 109 | +/** |
| 110 | + * Meter query result. |
| 111 | + */ |
| 112 | +@friendlyName("MeterQueryResult") |
| 113 | +@example(#{ |
| 114 | + from: Shared.DateTime.fromISO("2023-01-01T00:00:00Z"), |
| 115 | + to: Shared.DateTime.fromISO("2023-01-02T00:00:00Z"), |
| 116 | + data: #[ |
| 117 | + #{ |
| 118 | + value: "12.3456", |
| 119 | + from: Shared.DateTime.fromISO("2023-01-01T00:00:00Z"), |
| 120 | + to: Shared.DateTime.fromISO("2023-01-02T00:00:00Z"), |
| 121 | + subject_key: "83d489bd-13a5-4a3d-a886-44c385b5c43b", |
| 122 | + dimensions: #{ `model`: "gpt-4-turbo", type: "input" }, |
| 123 | + } |
| 124 | + ], |
| 125 | +}) |
| 126 | +model MeterQueryResult { |
| 127 | + /** |
| 128 | + * The start of the period the usage is queried from. |
| 129 | + */ |
| 130 | + from?: Shared.DateTime; |
| 131 | + |
| 132 | + /** |
| 133 | + * The end of the period the usage is queried to. |
| 134 | + */ |
| 135 | + to?: Shared.DateTime; |
| 136 | + |
| 137 | + /** |
| 138 | + * The usage data. |
| 139 | + * If no data is available, an empty array is returned. |
| 140 | + */ |
| 141 | + data: MeterQueryRow[]; |
| 142 | +} |
| 143 | + |
| 144 | +/** |
| 145 | + * A row in the result of a meter query. |
| 146 | + */ |
| 147 | +#suppress "@openmeter/api-spec/repeated-prefix-grouping" "keep the row flat" |
| 148 | +@friendlyName("MeterQueryRow") |
| 149 | +@example(#{ |
| 150 | + value: "12.3456", |
| 151 | + from: Shared.DateTime.fromISO("2023-01-01T00:00:00Z"), |
| 152 | + to: Shared.DateTime.fromISO("2023-01-02T00:00:00Z"), |
| 153 | + subject_key: "83d489bd-13a5-4a3d-a886-44c385b5c43b", |
| 154 | + dimensions: #{ `model`: "gpt-4-turbo", type: "input" }, |
| 155 | +}) |
| 156 | +model MeterQueryRow { |
| 157 | + /** |
| 158 | + * The aggregated value. |
| 159 | + */ |
| 160 | + value: Shared.Numeric; |
| 161 | + |
| 162 | + /** |
| 163 | + * The start of the time bucket the value is aggregated over. |
| 164 | + */ |
| 165 | + from: Shared.DateTime; |
| 166 | + |
| 167 | + /** |
| 168 | + * The end of the time bucket the value is aggregated over. |
| 169 | + */ |
| 170 | + to: Shared.DateTime; |
| 171 | + |
| 172 | + /** |
| 173 | + * The subject key the value is aggregated over. |
| 174 | + * If not specified, the value is aggregated over all subjects. |
| 175 | + */ |
| 176 | + subject_key?: string; |
| 177 | + |
| 178 | + /** |
| 179 | + * The customer ID the value is aggregated over. |
| 180 | + */ |
| 181 | + customer_id?: string; |
| 182 | + |
| 183 | + /** |
| 184 | + * The dimensions the value is aggregated over. |
| 185 | + */ |
| 186 | + dimensions: Record<string | null>; |
| 187 | +} |
0 commit comments