Skip to content

Commit 7582fd3

Browse files
authored
Merge pull request #231290 from mrbullwinkle/mrb_03_18_2023_openai_reference
[Cognitive Services] [Release branch] [Reference]
2 parents 9e01201 + 66b6c7c commit 7582fd3

File tree

1 file changed

+70
-25
lines changed

1 file changed

+70
-25
lines changed

articles/cognitive-services/openai/reference.md

Lines changed: 70 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,22 @@ manager: nitinme
77
ms.service: cognitive-services
88
ms.subservice: openai
99
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
1313
recommendations: false
1414
ms.custom:
1515
---
1616

1717
# Azure OpenAI Service REST API reference
1818

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.
27-
28-
[**Management APIs reference documentation**](/rest/api/cognitiveservices/)
19+
This article provides details on the inference REST API endpoints for Azure OpenAI.
2920

3021
## Authentication
3122

3223
Azure OpenAI provides two methods for authentication. you can use either API Keys or Azure Active Directory.
3324

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.
3526

3627
- **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).
3728

@@ -43,9 +34,8 @@ The service APIs are versioned using the ```api-version``` query parameter. All
4334
POST https://YOUR_RESOURCE_NAME.openai.azure.com/openai/deployments/YOUR_DEPLOYMENT_NAME/completions?api-version=2022-12-01
4435
```
4536

46-
We currently have the following versions available: ```2022-12-01```
47-
4837
## Completions
38+
4939
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.
5040

5141
**Create a completion**
@@ -59,30 +49,33 @@ POST https://{your-resource-name}.openai.azure.com/openai/deployments/{deploymen
5949
| Parameter | Type | Required? | Description |
6050
|--|--|--|--|
6151
| ```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. |
6353
| ```api-version``` | string | Required |The API version to use for this operation. This follows the YYYY-MM-DD format. |
6454

6555
**Supported versions**
6656

67-
- `2022-12-01`
57+
- `2023-03-15-preview` [Swagger spec](https://github.com/Azure/azure-rest-api-specs/blob/main/specification/cognitiveservices/data-plane/AzureOpenAI/inference/preview/2023-03-15-preview/inference.json)
58+
- `2022-12-01` [Swagger spec](https://github.com/Azure/azure-rest-api-specs/blob/main/specification/cognitiveservices/data-plane/AzureOpenAI/inference/stable/2022-12-01/inference.json)
6859

6960
**Request body**
7061

7162
| Parameter | Type | Required? | Default | Description |
7263
|--|--|--|--|--|
7364
| ```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). |
7566
| ```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. |
7667
| ```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 |
7770
| ```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. |
7871
| ```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.|
7972
| ```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. |
8074
| ```echo``` | boolean | Optional | False | Echo back the prompt in addition to the completion. This parameter cannot be used with `gpt-35-turbo`. |
8175
| ```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. |
8276
| ```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. |
8377
| ```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. |
8478
| ```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. |
8679

8780
#### Example request
8881

@@ -116,7 +109,7 @@ curl https://YOUR_RESOURCE_NAME.openai.azure.com/openai/deployments/YOUR_DEPLOYM
116109
```
117110

118111
## Embeddings
119-
Get a vector representation of a given input that can be easily consumed by machine learning models and other algorithms.
112+
Get a vector representation of a given input that can be easily consumed by machine learning models and other algorithms.
120113

121114
**Create an embedding**
122115

@@ -134,7 +127,8 @@ POST https://{your-resource-name}.openai.azure.com/openai/deployments/{deploymen
134127

135128
**Supported versions**
136129

137-
- `2022-12-01`
130+
- `2023-03-15-preview` [Swagger spec](https://github.com/Azure/azure-rest-api-specs/blob/main/specification/cognitiveservices/data-plane/AzureOpenAI/inference/preview/2023-03-15-preview/inference.json)
131+
- `2022-12-01` [Swagger spec](https://github.com/Azure/azure-rest-api-specs/blob/main/specification/cognitiveservices/data-plane/AzureOpenAI/inference/stable/2022-12-01/inference.json)
138132

139133
**Request body**
140134

@@ -146,7 +140,7 @@ POST https://{your-resource-name}.openai.azure.com/openai/deployments/{deploymen
146140
#### Example request
147141

148142
```console
149-
curl https://YOUR_RESOURCE_NAME.openai.azure.com/openai/deployments/YOUR_DEPLOYMENT_NAME/embeddings?api-version=2022-12-01\
143+
curl https://YOUR_RESOURCE_NAME.openai.azure.com/openai/deployments/YOUR_DEPLOYMENT_NAME/embeddings?api-version=2022-12-01 \
150144
-H "Content-Type: application/json" \
151145
-H "api-key: YOUR_API_KEY" \
152146
-d "{\"input\": \"The food was delicious and the waiter...\"}"
@@ -173,7 +167,58 @@ curl https://YOUR_RESOURCE_NAME.openai.azure.com/openai/deployments/YOUR_DEPLOYM
173167
}
174168
```
175169

170+
## Chat completions
171+
172+
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. |
187+
188+
**Supported versions**
189+
190+
- `2023-03-15-preview` [Swagger spec](https://github.com/Azure/azure-rest-api-specs/blob/main/specification/cognitiveservices/data-plane/AzureOpenAI/inference/preview/2023-03-15-preview/inference.json)
191+
192+
#### Example request
193+
194+
```console
195+
curl https://YOUR_RESOURCE_NAME.openai.azure.com/openai/deployments/YOUR_DEPLOYMENT_NAME/chat/completions?api-version=2023-03-15-preview \
196+
-H "Content-Type: application/json" \
197+
-H "api-key: YOUR_API_KEY" \
198+
-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?"}]}'
199+
200+
```
201+
202+
| Parameter | Type | Required? | Default | Description |
203+
|--|--|--|--|--|
204+
| ```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.
218+
219+
[**Management APIs reference documentation**](/rest/api/cognitiveservices/)
220+
176221
## Next steps
177222

178-
Learn about [managing deployments, models, and finetuning with the REST API](/rest/api/cognitiveservices/azureopenaistable/deployments/create).
179-
Learn more about the [underlying models that power Azure OpenAI](./concepts/models.md).
223+
Learn about [managing deployments, models, and fine-tuning with the REST API](/rest/api/cognitiveservices/azureopenaistable/deployments/create).
224+
Learn more about the [underlying models that power Azure OpenAI](./concepts/models.md).

0 commit comments

Comments
 (0)