You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/cognitive-services/openai/reference.md
+70-25Lines changed: 70 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,31 +7,22 @@ manager: nitinme
7
7
ms.service: cognitive-services
8
8
ms.subservice: openai
9
9
ms.topic: conceptual
10
-
ms.date: 11/17/2022
11
-
author: ChrisHMSFT
12
-
ms.author: chrhoder
10
+
ms.date: 03/21/2023
11
+
author: mrbullwinkle
12
+
ms.author: mbullwin
13
13
recommendations: false
14
14
ms.custom:
15
15
---
16
16
17
17
# Azure OpenAI Service REST API reference
18
18
19
-
This article provides details on the REST API endpoints for Azure OpenAI, a service in the Azure Cognitive Services suite. The REST APIs are broken up into two categories:
20
-
21
-
***Management APIs**: The Azure Resource Manager (ARM) provides the management layer in Azure that allows you to create, update and delete resource in Azure. All services use a common structure for these operations. [Learn More](../../azure-resource-manager/management/overview.md)
22
-
***Service APIs**: Azure OpenAI provides you with a set of REST APIs for interacting with the resources & models you deploy via the Management APIs.
23
-
24
-
## Management APIs
25
-
26
-
Azure OpenAI is deployed as a part of the Azure Cognitive Services. All Cognitive Services rely on the same set of management APIs for creation, update and delete operations. The management APIs are also used for deploying models within an OpenAI resource.
This article provides details on the inference REST API endpoints for Azure OpenAI.
29
20
30
21
## Authentication
31
22
32
23
Azure OpenAI provides two methods for authentication. you can use either API Keys or Azure Active Directory.
33
24
34
-
-**API Key authentication**: For this type of authentication, all API requests must include the API Key in the ```api-key``` HTTP header. The [Quickstart](./quickstart.md) provides a tutorial for how to make calls with this type of authentication
25
+
-**API Key authentication**: For this type of authentication, all API requests must include the API Key in the ```api-key``` HTTP header. The [Quickstart](./quickstart.md) provides guidance for how to make calls with this type of authentication.
35
26
36
27
-**Azure Active Directory authentication**: You can authenticate an API call using an Azure Active Directory token. Authentication tokens are included in a request as the ```Authorization``` header. The token provided must be preceded by ```Bearer```, for example ```Bearer YOUR_AUTH_TOKEN```. You can read our how-to guide on [authenticating with Azure Active Directory](./how-to/managed-identity.md).
37
28
@@ -43,9 +34,8 @@ The service APIs are versioned using the ```api-version``` query parameter. All
43
34
POST https://YOUR_RESOURCE_NAME.openai.azure.com/openai/deployments/YOUR_DEPLOYMENT_NAME/completions?api-version=2022-12-01
44
35
```
45
36
46
-
We currently have the following versions available: ```2022-12-01```
47
-
48
37
## Completions
38
+
49
39
With the Completions operation, the model will generate one or more predicted completions based on a provided prompt. The service can also return the probabilities of alternative tokens at each position.
50
40
51
41
**Create a completion**
@@ -59,30 +49,33 @@ POST https://{your-resource-name}.openai.azure.com/openai/deployments/{deploymen
59
49
| Parameter | Type | Required? | Description |
60
50
|--|--|--|--|
61
51
|```your-resource-name```| string | Required | The name of your Azure OpenAI Resource. |
62
-
|```deployment-id```| string | Required | The name of your model deployment. You're required to first deploy a model before you can make calls|
52
+
|```deployment-id```| string | Required | The deployment name you chose when you deployed the model. |
63
53
|```api-version```| string | Required |The API version to use for this operation. This follows the YYYY-MM-DD format. |
|```prompt```| string or array | Optional |```<\|endoftext\|>```| The prompt(s) to generate completions for, encoded as a string, a list of strings, or a list of token lists. Note that ```<\|endoftext\|>``` is the document separator that the model sees during training, so if a prompt isn't specified the model will generate as if from the beginning of a new document. |
74
-
|```max_tokens```| integer | Optional | 16 | The maximum number of tokens to generate in the completion. The token count of your prompt plus max_tokens can't exceed the model's context length. Most models have a context length of 2048 tokens (except davinci-codex, which supports 4096). |
65
+
|```max_tokens```| integer | Optional | 16 | The maximum number of tokens to generate in the completion. The token count of your prompt plus max_tokens can't exceed the model's context length. Most models have a context length of 2048 tokens (except for the newest models, which support 4096). |
75
66
|```temperature```| number | Optional | 1 | What sampling temperature to use. Higher values means the model will take more risks. Try 0.9 for more creative applications, and 0 (`argmax sampling`) for ones with a well-defined answer. We generally recommend altering this or top_p but not both. |
76
67
|```top_p```| number | Optional | 1 | An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or temperature but not both. |
68
+
|```logit_bias```| map | Optional | null | Modify the likelihood of specified tokens appearing in the completion. Accepts a json object that maps tokens (specified by their token ID in the GPT tokenizer) to an associated bias value from -100 to 100. You can use this tokenizer tool (which works for both GPT-2 and GPT-3) to convert text to token IDs. Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token. As an example, you can pass {"50256": -100} to prevent the <\|endoftext\|> token from being generated. |
69
+
|```user```| string | Optional || A unique identifier representing your end-user, which can help monitoring and detecting abuse |
77
70
|```n```| integer | Optional | 1 | How many completions to generate for each prompt. Note: Because this parameter generates many completions, it can quickly consume your token quota. Use carefully and ensure that you have reasonable settings for max_tokens and stop. |
78
71
|```stream```| boolean | Optional | False | Whether to stream back partial progress. If set, tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a data: [DONE] message.|
79
72
|```logprobs```| integer | Optional | null | Include the log probabilities on the logprobs most likely tokens, as well the chosen tokens. For example, if logprobs is 10, the API will return a list of the 10 most likely tokens. the API will always return the logprob of the sampled token, so there may be up to logprobs+1 elements in the response. This parameter cannot be used with `gpt-35-turbo`. |
73
+
|```suffix```| string | Optional | null | he suffix that comes after a completion of inserted text. |
80
74
|```echo```| boolean | Optional | False | Echo back the prompt in addition to the completion. This parameter cannot be used with `gpt-35-turbo`. |
81
75
|```stop```| string or array | Optional | null | Up to four sequences where the API will stop generating further tokens. The returned text won't contain the stop sequence. |
82
76
|```presence_penalty```| number | Optional | 0 | Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics. |
83
77
|```frequency_penalty```| number | Optional | 0 | Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim. |
84
78
|```best_of```| integer | Optional | 1 | Generates best_of completions server-side and returns the "best" (the one with the lowest log probability per token). Results can't be streamed. When used with n, best_of controls the number of candidate completions and n specifies how many to return – best_of must be greater than n. Note: Because this parameter generates many completions, it can quickly consume your token quota. Use carefully and ensure that you have reasonable settings for max_tokens and stop. This parameter cannot be used with `gpt-35-turbo`. |
85
-
|```logit_bias```| map | Optional | null | Modify the likelihood of specified tokens appearing in the completion. Accepts a json object that maps tokens (specified by their token ID in the GPT tokenizer) to an associated bias value from -100 to 100. You can use this tokenizer tool (which works for both GPT-2 and GPT-3) to convert text to token IDs. Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token. As an example, you can pass {"50256": -100} to prevent the <\|endoftext\|> token from being generated. |
Create completions for chat messages with the ChatGPT and GPT-4 models. Chat completions are currently only available with `api-version=2023-03-15-preview`.
173
+
174
+
**Create chat completions**
175
+
176
+
```http
177
+
POST https://{your-resource-name}.openai.azure.com/openai/deployments/{deployment-id}/chat/completions?api-version={api-version}
178
+
```
179
+
180
+
**Path parameters**
181
+
182
+
| Parameter | Type | Required? | Description |
183
+
|--|--|--|--|
184
+
|```your-resource-name```| string | Required | The name of your Azure OpenAI Resource. |
185
+
|```deployment-id```| string | Required | The name of your model deployment. You're required to first deploy a model before you can make calls |
186
+
|```api-version```| string | Required |The API version to use for this operation. This follows the YYYY-MM-DD format. |
-d '{"messages":[{"role": "system", "content": "You are a helpful assistant."},{"role": "user", "content": "Does Azure OpenAI support customer managed keys?"},{"role": "assistant", "content": "Yes, customer managed keys are supported by Azure OpenAI."},{"role": "user", "content": "Do other Azure Cognitive Services support this too?"}]}'
|```messages```| array | Required || The messages to generate chat completions for, in the chat format. |
205
+
|```temperature```| number | Optional | 1 | What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.\nWe generally recommend altering this or `top_p` but not both. |
206
+
|```n```| integer | Optional | 1 | How many chat completion choices to generate for each input message. |
207
+
|```stream```| boolean | Optional | false | If set, partial message deltas will be sent, like in ChatGPT. Tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a `data: [DONE]` message." |
208
+
|```stop```| string or array | Optional | null | Up to 4 sequences where the API will stop generating further tokens.|
209
+
|```max_tokens```| integer | Optional | inf | The maximum number of tokens allowed for the generated answer. By default, the number of tokens the model can return will be (4096 - prompt tokens).|
210
+
|```presence_penalty```| number | Optional | 0 | Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.|
211
+
|```frequency_penalty```| number | Optional | 0 | Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.|
212
+
|```logit_bias```| object | Optional | null | Modify the likelihood of specified tokens appearing in the completion. Accepts a json object that maps tokens (specified by their token ID in the tokenizer) to an associated bias value from -100 to 100. Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token.|
213
+
|```user```| string | Optional || A unique identifier representing your end-user, which can help Azure OpenAI to monitor and detect abuse.|
214
+
215
+
## Management APIs
216
+
217
+
Azure OpenAI is deployed as a part of the Azure Cognitive Services. All Cognitive Services rely on the same set of management APIs for creation, update and delete operations. The management APIs are also used for deploying models within an OpenAI resource.
0 commit comments