Skip to main content

OpenAI API - Getting Started

warning

This API is deprecated and will be removed in the coming weeks. Please use GenAI Azure OpenAI Inference API instead.

Introduction

if API Portal is probably new for you. We recommend to first have a look to echo API - getting started.

SF OpenAI API is protected by MFA and requires a subscription key.

The purpose of this documentation is to explain the different steps to access to APIM and execute your first API call using the Developer Portal.

Requirements

Access to Trustnest APIM

First, open your favorite browser and access to https://trustnest.developer.azure-api.net/

You should see :

img

Sign in for the first time

Click on "Sign in" buttun or "Sign in with AAD" in the top menu:

img

Click on "Azure Active Directory", you should be redirected to thalesdigital.io SSO:

img

note

During the first access, an additional step will ask you to fill/confirm your email. this is normal ! Give it and continue the steps.

Get a subscription key for Beta API Product

To access to an API, you should have a valid subscription key. Go to Product (on the top menu).

img

Select Beta API,

img

Click on "Subscribe" (Yellow Button), then you should be redirected to the postIT item: "Subscribe to Trustnest APIM":

img

Fill with:

  • TDFaccountID
  • APIM offer. For OpenAI: choose Openai API (APIM Beta API)

Click on Request

info

This item will follow the approval process and escalated to support level 2. A subscription key will be configured directly to APIM by level 2.

Once the subscription key is created, you should see it in the Product Page. Click on Beta API Product Page:

img

Access to SF OpenAI API

img

Scroll down, and select Software Factory OpenAI API

img

Make a request to OpenAI API

Click on "Try it" (green button on the right),

img

Authorization section:

  • (OPTIONAL) Oauth-AuthorizationCodeFlow: Select "authorization_code" it will open a popup windows and get an AAD token using your active session (it's transparent for you) (OPTIONAL from APIM release V3)
  • Subscription key: By default, your subscription is selected by default

Headers:

  • keep it as is

Body: You should see, by default:

{
"messages": [{
"role": "system",
"content": "You are an AI assistant that helps people find information."
}, {
"role": "user",
"content": "Hi"
}],
"temperature": 0.7,
"top_p": 0.95,
"frequency_penalty": 0,
"presence_penalty": 0,
"max_tokens": 800,
"stop": ""
}

You can update the content field with a custom question.

Finally, click on send, you should see a return code 200, with an output like:

{
"id": "chatcmpl-7gdLhlYqE1jNGBzPdb8I8qXoPi12M",
"object": "chat.completion",
"created": 1690395389,
"model": "gpt-35-turbo",
"choices": [{
"index": 0,
"finish_reason": "stop",
"message": {
"role": "assistant",
"content": "Hello! How can I assist you today?"
}
}],
"usage": {
"completion_tokens": 9,
"prompt_tokens": 25,
"total_tokens": 34
}
}

img

TROUBLESHOOTING

500 internal Server Error

img

Usually, you get a 500 error when the body is not properly formatted. Check the JSON validity of your body, for instance using https://jsonlint.com/ if your data is C1. Or using a command line jq on your laptop if your data is C2 or higher.

note

your issue is not listed here ?

  • have a look to the troubleshooting section located in the homepage
  • raise a request using postIT to help us improving this documentation