-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
apiManagement.bicep
168 lines (158 loc) · 3.83 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
param openAiEndpoint string
param openAiApiKey string
param appInsightsInstrumentationKey string
param appInsightsId string
param rgLocation string
param rgId string = substring(uniqueString(resourceGroup().id), 0, 8)
resource apiManagementService 'Microsoft.ApiManagement/service@2023-03-01-preview' = {
name: 'OpenAI-API-${rgId}'
location: rgLocation
sku: {
name: 'Consumption'
capacity: 0
}
properties: {
publisherEmail: 'info@example.com'
publisherName: 'OpenAI Publisher'
}
}
/*
todos
- add keyvault for named value on api? might be dumb, because we need the api key at some point anyway
-
*/
var endpoint = '${openAiEndpoint}/openai'
resource openAiApiProxy 'Microsoft.ApiManagement/service/apis@2023-03-01-preview' = {
parent: apiManagementService
name: 'OpenAIProxy'
properties: {
serviceUrl: endpoint
path: 'openai'
displayName: 'OpenAI Proxy API' // Added display name
protocols: [ 'https' ]
format: 'openapi-link'
value: 'https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/cognitiveservices/data-plane/AzureOpenAI/inference/stable/2023-05-15/inference.json'
subscriptionRequired: true
subscriptionKeyParameterNames: {
header: 'api-key'
query: 'api-key'
}
}
}
resource apiSubscription 'Microsoft.ApiManagement/service/subscriptions@2023-03-01-preview' = {
parent: apiManagementService
name: 'OpenAI-Subscription'
properties: {
scope: openAiApiProxy.id
displayName: 'OpenAI Subscription'
state: 'active'
}
}
resource inboundPolicy 'Microsoft.ApiManagement/service/apis/policies@2023-03-01-preview' = {
parent: openAiApiProxy
name: 'policy'
properties: {
format: 'rawxml'
value: '''
<policies>
<inbound>
<base />
<set-backend-service backend-id="backend" />
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>
'''
}
}
resource apiBackend 'Microsoft.ApiManagement/service/backends@2023-03-01-preview' = {
parent: apiManagementService
name: 'backend'
properties: {
url: endpoint
protocol: 'http'
title: 'OpenAI API'
description: 'OpenAI API'
tls: {
validateCertificateChain: true
validateCertificateName: true
}
credentials: {
header: {
'api-key': [ openAiApiKey ]
}
}
}
}
resource apiManagementLogger 'Microsoft.ApiManagement/service/loggers@2020-06-01-preview' = {
parent: apiManagementService
name: 'OpenAI-Logger'
properties: {
loggerType: 'applicationInsights'
description: 'Logger for OpenAI API calls'
resourceId: appInsightsId
credentials: {
instrumentationKey: appInsightsInstrumentationKey
}
}
}
resource apiDiagnostics 'Microsoft.ApiManagement/service/apis/diagnostics@2023-03-01-preview' = {
name: 'applicationinsights'
parent: openAiApiProxy
properties: {
logClientIp: false
alwaysLog: 'allErrors'
loggerId: apiManagementLogger.id
sampling: {
samplingType: 'fixed'
percentage: 100
}
metrics: true
frontend: {
request: {
headers: [
'custom-headers'
]
body: {
bytes: 8192
}
}
response: {
headers: [
'custom-headers'
]
body: {
bytes: 8192
}
}
}
backend: {
request: {
headers: [
'custom-headers'
]
body: {
bytes: 8192
}
}
response: {
headers: [
'custom-headers'
]
body: {
bytes: 8192
}
}
}
verbosity: 'information'
}
}
output url string = openAiApiProxy.properties.serviceUrl
output gatewayUrl string = apiManagementService.properties.gatewayUrl