Integrating with Azure OpenAI
This tutorial shows how to use the Cape API to make an Azure OpenAI chat completion request. Cape will automatically redact sensitive entities like PII, PCI, and PHI so they are not shared with the model. And then Cape will re-identify the redacted entities before returning the response to the caller.
Get a Cape API Key
This tutorial assumes you have an environment variable CAPE_API_KEY
that contains an API Key.
You will need to signup for a Cape account, and then you can get an API key here.
Using the Cape API to call Azure OpenAI
Here's how to use Python to make a request to the Cape API when targeting Azure OpenAI models. Please see the API docs for more details.
import os
import requests
url = "https://api.capeprivacy.com/v1/azure/completions"
payload = {
"model": "gpt-4-32k",
"messages": [
{"role": "system", "content": "Bob is a software engineer who works at the company Cape Privacy!"},
{"role": "user", "content": "What company does Bob work for?"}
],
"format": "redacted",
"extra_openai": {
"temperature": 1
}
}
headers = {
"content-type": "application/json",
"Authorization": f"Bearer {os.getenv('CAPE_API_KEY')}"
}
response = requests.post(url, json=payload, headers=headers)
data = response.json()
print(data)
Output
{
"id": "capeapi-b2e07f52-128e-46b1-82c0-ebb4f6fa86ae",
"object": "chat.completion",
"created": 1692046391.4658444,
"model": "azure-gpt-4-32k",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Bob works for the company Cape Privacy."
},
"finish_reason": "stop"
}
]
}
That's it! To recap, Cape automatically redacted any sensitive entities so they were not
sent to Azure OpenAI (for example, Bob
became [NAME_GIVEN_1]
). And then Cape also re-identified the
redacted entities from the Azure OpenAI response (eg [NAME_GIVEN_1]
was replaced back to Bob
).