-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathapiManagement.bicep
822 lines (747 loc) · 24.3 KB
/
apiManagement.bicep
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
@description('The name of the API Management service instance')
param apiManagementServiceName string
@description('The email address of the owner of the service')
param publisherEmail string = 'apim@contoso.com'
@description('The name of the owner of the service')
param publisherName string = 'Contoso'
@description('The pricing tier of this API Management service')
@allowed([
'Consumption'
'Developer'
'Basic'
'Standard'
'Premium'
])
param sku string = 'Developer'
@description('The instance size of this API Management service.')
@allowed([
0
1
2
])
param skuCount int = 1
@description('The base url of the first Azure Open AI Service PTU deployment (e.g. https://{your-resource-name}.openai.azure.com/openai/deployments/{deployment-id}/)')
param ptuDeploymentOneBaseUrl string
@description('The api key of the first Azure Open AI Service PTU deployment')
param ptuDeploymentOneApiKey string
@description('The base url of the first Azure Open AI Service Pay-As-You-Go deployment (e.g. https://{your-resource-name}.openai.azure.com/openai/deployments/{deployment-id}/)')
param payAsYouGoDeploymentOneBaseUrl string
@description('The api key of the first Azure Open AI Service Pay-As-You-Go deployment')
param payAsYouGoDeploymentOneApiKey string
@description('The base url of the second Azure Open AI Service Pay-As-You-Go deployment (e.g. https://{your-resource-name}.openai.azure.com/openai/deployments/{deployment-id}/)')
param payAsYouGoDeploymentTwoBaseUrl string
@description('The api key of the second Azure Open AI Service Pay-As-You-Go deployment')
param payAsYouGoDeploymentTwoApiKey string
@description('The name of the Event Hub Namespace to log to')
param eventHubNamespaceName string
@description('The name of the Event Hub to log utilization data to')
param eventHubName string
@description('The name of the Log Analytics workspace')
param logAnalyticsName string
@description('The name of the App Insights instance')
param appInsightsName string
@description('Location for all resources.')
param location string = resourceGroup().location
resource apiManagementService 'Microsoft.ApiManagement/service@2024-05-01' = {
name: apiManagementServiceName
location: location
sku: {
name: sku
capacity: skuCount
}
properties: {
publisherEmail: publisherEmail
publisherName: publisherName
apiVersionConstraint: {
minApiVersion: '2019-12-01'
}
}
identity: {
type: 'SystemAssigned'
}
}
resource azureOpenAISimpleRoundRobinAPI 'Microsoft.ApiManagement/service/apis@2024-05-01' = {
parent: apiManagementService
name: 'aoai-api-simple-round-robin'
properties: {
path: '/round-robin-simple/openai'
displayName: 'AOAIAPI-SimpleRoundRobin'
protocols: ['https']
value: loadTextContent('../api-specs/openapi-spec.json')
format: 'openapi+json'
subscriptionKeyParameterNames: {
header: 'api-key'
}
}
}
resource azureOpenAISimpleRoundRobinAPIv2 'Microsoft.ApiManagement/service/apis@2024-05-01' = {
parent: apiManagementService
name: 'aoai-api-simple-round-robin-v2'
properties: {
path: '/round-robin-simple-v2/openai'
displayName: 'AOAIAPI-SimpleRoundRobin-V2'
protocols: ['https']
value: loadTextContent('../api-specs/openapi-spec.json')
format: 'openapi+json'
subscriptionKeyParameterNames: {
header: 'api-key'
}
}
}
resource azureOpenAIWeightedRoundRobinAPI 'Microsoft.ApiManagement/service/apis@2024-05-01' = {
parent: apiManagementService
name: 'aoai-api-weighted-round-robin'
properties: {
path: '/round-robin-weighted/openai'
displayName: 'AOAIAPI-WeightedRoundRobin'
protocols: ['https']
value: loadTextContent('../api-specs/openapi-spec.json')
format: 'openapi+json'
subscriptionKeyParameterNames: {
header: 'api-key'
}
}
}
resource azureOpenAIWeightedRoundRobinAPIv2 'Microsoft.ApiManagement/service/apis@2024-05-01' = {
parent: apiManagementService
name: 'aoai-api-weighted-round-robin-v2'
properties: {
path: '/round-robin-weighted-v2/openai'
displayName: 'AOAIAPI-WeightedRoundRobin-V2'
protocols: ['https']
value: loadTextContent('../api-specs/openapi-spec.json')
format: 'openapi+json'
subscriptionKeyParameterNames: {
header: 'api-key'
}
}
}
resource azureOpenAIRetryWithPayAsYouGoAPI 'Microsoft.ApiManagement/service/apis@2024-05-01' = {
parent: apiManagementService
name: 'aoai-api-retry-with-payg'
properties: {
path: '/retry-with-payg/openai'
displayName: 'AOAIAPI-RetryWithPayAsYouGo'
protocols: ['https']
value: loadTextContent('../api-specs/openapi-spec.json')
format: 'openapi+json'
subscriptionKeyParameterNames: {
header: 'api-key'
}
}
}
resource azureOpenAIRetryWithPayAsYouGoAPIv2 'Microsoft.ApiManagement/service/apis@2024-05-01' = {
parent: apiManagementService
name: 'aoai-api-retry-with-payg-v2'
properties: {
path: '/retry-with-payg-v2/openai'
displayName: 'AOAIAPI-RetryWithPayAsYouGo-V2'
protocols: ['https']
value: loadTextContent('../api-specs/openapi-spec.json')
format: 'openapi+json'
subscriptionKeyParameterNames: {
header: 'api-key'
}
}
}
resource azureOpenAILatencyRoutingAPI 'Microsoft.ApiManagement/service/apis@2024-05-01' = {
parent: apiManagementService
name: 'aoai-api-latency-routing'
properties: {
path: '/latency-routing/openai'
displayName: 'AOAIAPI-LatencyRouting'
protocols: ['https']
value: loadTextContent('../api-specs/openapi-spec.json')
format: 'openapi+json'
subscriptionKeyParameterNames: {
header: 'api-key'
}
}
}
resource azureOpenAIUsageTrackingAPI 'Microsoft.ApiManagement/service/apis@2024-05-01' = {
parent: apiManagementService
name: 'aoai-api-usage-tracking'
properties: {
path: '/usage-tracking/openai'
displayName: 'AOAIAPI-UsageTracking'
protocols: ['https']
value: loadTextContent('../api-specs/openapi-spec.json')
format: 'openapi+json'
subscriptionKeyParameterNames: {
header: 'api-key'
}
}
}
resource azureOpenAIPrioritizationTokenCalculatingAPI 'Microsoft.ApiManagement/service/apis@2024-05-01' = {
parent: apiManagementService
name: 'aoai-api-prioritization-token-calculating'
properties: {
path: '/prioritization-token-calculating/openai'
displayName: 'AOAIAPI-Prioritization-TokenCalculating'
protocols: ['https']
value: loadTextContent('../api-specs/openapi-spec.json')
format: 'openapi+json'
subscriptionKeyParameterNames: {
header: 'api-key'
}
}
}
resource azureOpenAIPrioritizationTokenTrackingAPI 'Microsoft.ApiManagement/service/apis@2024-05-01' = {
parent: apiManagementService
name: 'aoai-api-prioritization-tracking'
properties: {
path: '/prioritization-token-tracking/openai'
displayName: 'AOAIAPI-Prioritization-TokenTracking'
protocols: ['https']
value: loadTextContent('../api-specs/openapi-spec.json')
format: 'openapi+json'
subscriptionKeyParameterNames: {
header: 'api-key'
}
}
}
resource helperAPI 'Microsoft.ApiManagement/service/apis@2024-05-01' = {
parent: apiManagementService
name: 'helper-apis'
properties: {
path: '/helpers'
displayName: 'Helper APIs'
protocols: ['https']
value: loadTextContent('../api-specs/support-api-spec.json')
format: 'openapi+json'
subscriptionKeyParameterNames: {
header: 'api-key'
}
}
}
resource azureOpenAIProduct 'Microsoft.ApiManagement/service/products@2024-05-01' = {
parent: apiManagementService
name: 'aoai-product'
properties: {
displayName: 'aoai-product'
subscriptionRequired: true
state: 'published'
approvalRequired: false
}
}
var azureOpenAIAPINames = [
azureOpenAISimpleRoundRobinAPI.name
azureOpenAISimpleRoundRobinAPIv2.name
azureOpenAIWeightedRoundRobinAPI.name
azureOpenAIWeightedRoundRobinAPIv2.name
azureOpenAIRetryWithPayAsYouGoAPI.name
azureOpenAIRetryWithPayAsYouGoAPIv2.name
azureOpenAILatencyRoutingAPI.name
azureOpenAIUsageTrackingAPI.name
azureOpenAIPrioritizationTokenCalculatingAPI.name
azureOpenAIPrioritizationTokenTrackingAPI.name
helperAPI.name
]
resource azureOpenAIProductAPIAssociation 'Microsoft.ApiManagement/service/products/apis@2024-05-01' = [
for apiName in azureOpenAIAPINames: {
name: '${apiManagementServiceName}/${azureOpenAIProduct.name}/${apiName}'
}
]
resource ptuBackendOne 'Microsoft.ApiManagement/service/backends@2024-05-01' = {
parent: apiManagementService
name: 'ptu-backend-1'
properties: {
protocol: 'http'
url: ptuDeploymentOneBaseUrl
credentials: {
header: {
'api-key': [ptuDeploymentOneApiKey]
}
}
}
}
resource ptuBackendOneWithCircuitBreaker 'Microsoft.ApiManagement/service/backends@2024-05-01' = {
parent: apiManagementService
name: 'ptu-backend-1-with-circuit-breaker'
properties: {
protocol: 'http'
url: ptuDeploymentOneBaseUrl
credentials: {
header: {
'api-key': [ptuDeploymentOneApiKey]
}
}
circuitBreaker: {
rules: [
{
failureCondition: {
count: 3
errorReasons: [
'429s'
]
interval: 'PT10S'
statusCodeRanges: [
{
min: 429
max: 429
}
]
}
name: 'retry-with-payg-breaker-rule'
tripDuration: 'PT1M'
acceptRetryAfter: true
}
]
}
}
}
resource payAsYouGoBackendOne 'Microsoft.ApiManagement/service/backends@2024-05-01' = {
parent: apiManagementService
name: 'payg-backend-1'
properties: {
protocol: 'http'
url: payAsYouGoDeploymentOneBaseUrl
credentials: {
header: {
'api-key': [payAsYouGoDeploymentOneApiKey]
}
}
}
}
resource payAsYouGoBackendTwo 'Microsoft.ApiManagement/service/backends@2024-05-01' = {
parent: apiManagementService
name: 'payg-backend-2'
properties: {
protocol: 'http'
url: payAsYouGoDeploymentTwoBaseUrl
credentials: {
header: {
'api-key': [payAsYouGoDeploymentTwoApiKey]
}
}
}
}
resource simpleRoundRobinBackendPool 'Microsoft.ApiManagement/service/backends@2023-09-01-preview' = {
parent: apiManagementService
name: 'simple-round-robin-backend-pool'
properties: {
type: 'Pool'
pool: {
services: [
{
id: payAsYouGoBackendOne.id
weight: 1
priority: 1
}
{
id: payAsYouGoBackendTwo.id
weight: 1
priority: 1
}
]
}
}
}
resource weightedRoundRobinBackendPool 'Microsoft.ApiManagement/service/backends@2023-09-01-preview' = {
parent: apiManagementService
name: 'weighted-round-robin-backend-pool'
properties: {
type: 'Pool'
pool: {
services: [
{
id: payAsYouGoBackendOne.id
weight: 2
priority: 1
}
{
id: payAsYouGoBackendTwo.id
weight: 1
priority: 1
}
]
}
}
}
resource retryWithPayAsYouGoBackendPool 'Microsoft.ApiManagement/service/backends@2023-09-01-preview' = {
parent: apiManagementService
name: 'retry-with-payg-backend-pool'
properties: {
type: 'Pool'
pool: {
services: [
{
id: ptuBackendOneWithCircuitBreaker.id
weight: 1
priority: 1
}
{
id: payAsYouGoBackendOne.id
weight: 1
priority: 2
}
]
}
}
}
resource azureOpenAIProductSubscriptionOne 'Microsoft.ApiManagement/service/subscriptions@2024-05-01' = {
parent: apiManagementService
name: 'aoai-product-subscription-one'
properties: {
displayName: 'aoai-product-subscription-one'
state: 'active'
scope: azureOpenAIProduct.id
}
}
resource azureOpenAIProductSubscriptionTwo 'Microsoft.ApiManagement/service/subscriptions@2024-05-01' = {
parent: apiManagementService
name: 'aoai-product-subscription-two'
properties: {
displayName: 'aoai-product-subscription-two'
state: 'active'
scope: azureOpenAIProduct.id
}
}
resource azureOpenAIProductSubscriptionThree 'Microsoft.ApiManagement/service/subscriptions@2024-05-01' = {
parent: apiManagementService
name: 'aoai-product-subscription-three'
properties: {
displayName: 'aoai-product-subscription-three'
state: 'active'
scope: azureOpenAIProduct.id
}
}
resource simpleRoundRobinPolicyFragment 'Microsoft.ApiManagement/service/policyFragments@2024-05-01' = {
parent: apiManagementService
name: 'simple-round-robin'
properties: {
value: loadTextContent('../../../capabilities/load-balancing/simple-round-robin.xml')
format: 'rawxml'
}
dependsOn: [payAsYouGoBackendOne, payAsYouGoBackendTwo]
}
resource azureOpenAISimpleRoundRobinAPIPolicy 'Microsoft.ApiManagement/service/apis/policies@2024-05-01' = {
parent: azureOpenAISimpleRoundRobinAPI
name: 'policy'
properties: {
value: loadTextContent('../../../capabilities/load-balancing/simple-round-robin-policy.xml')
format: 'rawxml'
}
dependsOn: [simpleRoundRobinPolicyFragment]
}
resource simpleRoundRobinPolicyFragmentv2 'Microsoft.ApiManagement/service/policyFragments@2024-05-01' = {
parent: apiManagementService
name: 'simple-round-robin-v2'
properties: {
value: loadTextContent('../../../capabilities/load-balancing-v2/simple-round-robin.xml')
format: 'rawxml'
}
dependsOn: [simpleRoundRobinBackendPool]
}
resource azureOpenAISimpleRoundRobinAPIPolicyv2 'Microsoft.ApiManagement/service/apis/policies@2024-05-01' = {
parent: azureOpenAISimpleRoundRobinAPIv2
name: 'policy'
properties: {
value: loadTextContent('../../../capabilities/load-balancing-v2/simple-round-robin-policy.xml')
format: 'rawxml'
}
dependsOn: [simpleRoundRobinPolicyFragmentv2]
}
resource weightedRoundRobinPolicyFragment 'Microsoft.ApiManagement/service/policyFragments@2024-05-01' = {
parent: apiManagementService
name: 'weighted-round-robin'
properties: {
value: loadTextContent('../../../capabilities/load-balancing/weighted-round-robin.xml')
format: 'rawxml'
}
dependsOn: [payAsYouGoBackendOne, payAsYouGoBackendTwo]
}
resource azureOpenAIWeightedRoundRobinAPIPolicy 'Microsoft.ApiManagement/service/apis/policies@2024-05-01' = {
parent: azureOpenAIWeightedRoundRobinAPI
name: 'policy'
properties: {
value: loadTextContent('../../../capabilities/load-balancing/weighted-round-robin-policy.xml')
format: 'rawxml'
}
dependsOn: [weightedRoundRobinPolicyFragment]
}
resource weightedRoundRobinPolicyFragmentv2 'Microsoft.ApiManagement/service/policyFragments@2024-05-01' = {
parent: apiManagementService
name: 'weighted-round-robin-v2'
properties: {
value: loadTextContent('../../../capabilities/load-balancing-v2/weighted-round-robin.xml')
format: 'rawxml'
}
dependsOn: [weightedRoundRobinBackendPool]
}
resource azureOpenAIWeightedRoundRobinAPIPolicyv2 'Microsoft.ApiManagement/service/apis/policies@2024-05-01' = {
parent: azureOpenAIWeightedRoundRobinAPIv2
name: 'policy'
properties: {
value: loadTextContent('../../../capabilities/load-balancing-v2/weighted-round-robin-policy.xml')
format: 'rawxml'
}
dependsOn: [weightedRoundRobinPolicyFragmentv2]
}
resource retryWithPayAsYouGoPolicyFragment 'Microsoft.ApiManagement/service/policyFragments@2024-05-01' = {
parent: apiManagementService
name: 'retry-with-payg'
properties: {
value: loadTextContent('../../../capabilities/manage-spikes-with-payg/retry-with-payg.xml')
format: 'rawxml'
}
dependsOn: [ptuBackendOne, payAsYouGoBackendOne]
}
resource azureOpenAIRetryWithPayAsYouGoAPIPolicy 'Microsoft.ApiManagement/service/apis/policies@2024-05-01' = {
parent: azureOpenAIRetryWithPayAsYouGoAPI
name: 'policy'
properties: {
value: loadTextContent('../../../capabilities/manage-spikes-with-payg/retry-with-payg-policy.xml')
format: 'rawxml'
}
dependsOn: [retryWithPayAsYouGoPolicyFragment]
}
resource retryWithPayAsYouGoPolicyFragmentv2 'Microsoft.ApiManagement/service/policyFragments@2024-05-01' = {
parent: apiManagementService
name: 'retry-with-payg-v2'
properties: {
value: loadTextContent('../../../capabilities/manage-spikes-with-payg-v2/retry-with-payg.xml')
format: 'rawxml'
}
dependsOn: [retryWithPayAsYouGoBackendPool]
}
resource azureOpenAIRetryWithPayAsYouGoAPIPolicyv2 'Microsoft.ApiManagement/service/apis/policies@2024-05-01' = {
parent: azureOpenAIRetryWithPayAsYouGoAPIv2
name: 'policy'
properties: {
value: loadTextContent('../../../capabilities/manage-spikes-with-payg-v2/retry-with-payg-policy.xml')
format: 'rawxml'
}
dependsOn: [retryWithPayAsYouGoPolicyFragmentv2]
}
resource latencyRoutingInboundPolicyFragment 'Microsoft.ApiManagement/service/policyFragments@2024-05-01' = {
parent: apiManagementService
name: 'latency-routing-inbound'
properties: {
value: loadTextContent('../../../capabilities/latency-routing/latency-routing-inbound.xml')
format: 'rawxml'
}
dependsOn: [payAsYouGoBackendOne]
}
resource latencyRoutingBackendPolicyFragment 'Microsoft.ApiManagement/service/policyFragments@2024-05-01' = {
parent: apiManagementService
name: 'latency-routing-backend'
properties: {
value: loadTextContent('../../../capabilities/latency-routing/latency-routing-backend.xml')
format: 'rawxml'
}
}
resource azureOpenAILatencyRoutingPolicy 'Microsoft.ApiManagement/service/apis/policies@2024-05-01' = {
parent: azureOpenAILatencyRoutingAPI
name: 'policy'
properties: {
value: loadTextContent('../../../capabilities/latency-routing/latency-routing-policy.xml')
format: 'rawxml'
}
dependsOn: [latencyRoutingInboundPolicyFragment, latencyRoutingBackendPolicyFragment]
}
resource usageTrackingPolicyFragmentInbound 'Microsoft.ApiManagement/service/policyFragments@2024-05-01' = {
parent: apiManagementService
name: 'usage-tracking-inbound'
properties: {
value: loadTextContent('../../../capabilities/usage-tracking/usage-tracking-inbound.xml')
format: 'rawxml'
}
dependsOn: [payAsYouGoBackendOne]
}
resource usageTrackingPolicyFragmentOutbound 'Microsoft.ApiManagement/service/policyFragments@2024-05-01' = {
parent: apiManagementService
name: 'usage-tracking-outbound'
properties: {
value: loadTextContent('../../../capabilities/usage-tracking/usage-tracking-outbound.xml')
format: 'rawxml'
}
dependsOn: [eventHubLogger]
}
resource azureOpenAIUsageTrackingPolicy 'Microsoft.ApiManagement/service/apis/policies@2024-05-01' = {
parent: azureOpenAIUsageTrackingAPI
name: 'policy'
properties: {
value: loadTextContent('../../../capabilities/usage-tracking/usage-tracking-policy.xml')
format: 'rawxml'
}
dependsOn: [usageTrackingPolicyFragmentInbound, usageTrackingPolicyFragmentOutbound]
}
resource azureOpenAIPrioritizationTokenCalculatingPolicy 'Microsoft.ApiManagement/service/apis/policies@2024-05-01' = {
parent: azureOpenAIPrioritizationTokenCalculatingAPI
name: 'policy'
properties: {
value: loadTextContent('../../../capabilities/prioritization/prioritization-token-calculating.xml')
format: 'rawxml'
}
}
resource azureOpenAIPrioritizationTokenTrackingPolicy 'Microsoft.ApiManagement/service/apis/policies@2024-05-01' = {
parent: azureOpenAIPrioritizationTokenTrackingAPI
name: 'policy'
properties: {
value: loadTextContent('../../../capabilities/prioritization/prioritization-token-tracking.xml')
format: 'rawxml'
}
}
resource helperAPISetPreferredBackends 'Microsoft.ApiManagement/service/apis/policies@2024-05-01' = {
parent: helperAPI
name: 'policy'
properties: {
value: loadTextContent('../../../capabilities/latency-routing/set-latency-policy.xml')
format: 'rawxml'
}
}
resource eventHubNamespace 'Microsoft.EventHub/namespaces@2021-11-01' existing = {
name: eventHubNamespaceName
}
resource eventHubsDataSenderRoleDefinition 'Microsoft.Authorization/roleDefinitions@2018-01-01-preview' existing = {
scope: eventHubNamespace
name: '2b629674-e913-4c01-ae53-ef4638d8f975' // https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles#azure-event-hubs-data-sender
}
resource assignEventHubsDataSenderToApiManagement 'Microsoft.Authorization/roleAssignments@2020-04-01-preview' = {
name: guid(
resourceGroup().id,
eventHubNamespace.name,
apiManagementService.name,
'assignEventHubsDataSenderToApiManagement'
)
scope: eventHubNamespace
properties: {
description: 'Assign EventHubsDataSender role to API Management'
principalId: apiManagementService.identity.principalId
principalType: 'ServicePrincipal'
roleDefinitionId: eventHubsDataSenderRoleDefinition.id
}
}
resource eventHubLogger 'Microsoft.ApiManagement/service/loggers@2022-04-01-preview' = {
name: 'eventhub-logger'
parent: apiManagementService
properties: {
loggerType: 'azureEventHub'
description: 'Event hub logger with system-assigned managed identity'
credentials: {
endpointAddress: '${eventHubNamespaceName}.servicebus.windows.net'
identityClientId: 'systemAssigned'
name: eventHubName
}
}
}
resource appInsights 'Microsoft.Insights/components@2020-02-02' existing = {
name: appInsightsName
}
resource appInsightsLogger 'Microsoft.ApiManagement/service/loggers@2022-04-01-preview' = {
name: 'appinsights-logger'
parent: apiManagementService
properties: {
loggerType: 'applicationInsights'
description: 'Application Insights logger'
resourceId: appInsights.id
credentials: {
instrumentationKey: appInsights.properties.InstrumentationKey
}
}
}
resource azureMonitorLogger 'Microsoft.ApiManagement/service/loggers@2022-04-01-preview' = {
name: 'azuremonitor'
parent: apiManagementService
properties: {
loggerType: 'azureMonitor'
isBuffered: true
}
}
resource allApisAzureMonitorDiagnostics 'Microsoft.ApiManagement/service/diagnostics@2024-05-01' = {
parent: apiManagementService
name: 'azuremonitor'
properties: {
loggerId: azureMonitorLogger.id
metrics: true
verbosity: 'information'
logClientIp: false
sampling: {
percentage: 100
samplingType: 'fixed'
}
frontend: {
request: {
headers: [
'x-priority'
]
}
response: {
headers: [
'x-gw-ratelimit-reason'
'x-gw-ratelimit-value'
'x-gw-remaining-tokens'
'x-gw-remaining-requests'
'x-gw-priority'
]
}
}
backend: {
request: {
headers: []
}
response: {
headers: [
'x-ratelimit-remaining-tokens'
'x-ratelimit-remaining-requests'
]
}
}
}
}
resource azureOpenAIUsageTrackingAPIDiagnostics 'Microsoft.ApiManagement/service/apis/diagnostics@2024-05-01' = {
parent: azureOpenAIUsageTrackingAPI
name: 'applicationinsights'
properties: {
loggerId: appInsightsLogger.id
metrics: true
}
}
resource azureOpenAIPrioritizationTokenCalculatingAPIDiagnostics 'Microsoft.ApiManagement/service/apis/diagnostics@2024-05-01' = {
parent: azureOpenAIPrioritizationTokenCalculatingAPI
name: 'applicationinsights'
properties: {
loggerId: appInsightsLogger.id
metrics: true
}
}
resource azureOpenAIPrioritizationTokenTrackingAPIDiagnostics 'Microsoft.ApiManagement/service/apis/diagnostics@2024-05-01' = {
parent: azureOpenAIPrioritizationTokenTrackingAPI
name: 'applicationinsights'
properties: {
loggerId: appInsightsLogger.id
metrics: true
}
}
resource logAnalytics 'Microsoft.OperationalInsights/workspaces@2021-12-01-preview' existing = {
name: logAnalyticsName
}
resource apiManagementDiagnosticSettings 'Microsoft.Insights/diagnosticSettings@2021-05-01-preview' = {
name: '${apiManagementServiceName}-diagnostic-settings'
scope: apiManagementService
properties: {
workspaceId: logAnalytics.id
logAnalyticsDestinationType: 'Dedicated'
logs: [
{
categoryGroup: 'allLogs'
enabled: true
}
{
categoryGroup: 'audit'
enabled: true
}
]
metrics: [
{
category: 'AllMetrics'
enabled: true
}
]
}
}
output apiManagementServiceName string = apiManagementService.name
output apiManagementAzureOpenAIProductSubscriptionOneKey string = azureOpenAIProductSubscriptionOne.listSecrets().primaryKey
output apiManagementAzureOpenAIProductSubscriptionTwoKey string = azureOpenAIProductSubscriptionTwo.listSecrets().primaryKey
output apiManagementAzureOpenAIProductSubscriptionThreeKey string = azureOpenAIProductSubscriptionThree.listSecrets().primaryKey