{"id":5115,"date":"2023-05-09T11:45:36","date_gmt":"2023-05-09T11:45:36","guid":{"rendered":"https:\/\/unremot.com\/blog\/?p=5115"},"modified":"2023-05-09T17:51:03","modified_gmt":"2023-05-09T17:51:03","slug":"how-to-use-chatgpt-api","status":"publish","type":"post","link":"https:\/\/unremot.com\/blog\/how-to-use-chatgpt-api\/","title":{"rendered":"How to use ChatGPT API &#8211; a step-by-step integration guide and full documentation list"},"content":{"rendered":"<p>This article will discuss how to use ChatGPT API. Let&#8217;s get started!<\/p>\n\n<h2><strong>Overview of ChatGPT API<\/strong><\/h2>\n<p><span style=\"font-weight: 400;\">ChatGPT is an upcoming and quite popular chatbot utilizing cutting-edge technologies. It is now an important criterion to use ChatGPT API and integrate it with the existing applications in a company for better usage.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In this article, we will learn about the steps of using OpenAI ChatGPT API and the documentation references of ChatGPT Official API.<\/span><\/p>\n<h2><strong>How to use ChatGPT API for text completion &#8211; step-by-step integration guide<\/strong><\/h2>\n<p><span style=\"font-weight: 400;\">In the first section, we will discover the steps for how to use ChatGPT API for text completion. You need to use the completion endpoint in <a href=\"https:\/\/openai.com\/blog\/chatgpt\" target=\"_blank\" rel=\"noopener\">ChatGPT<\/a> API to accomplish many tasks, which serves as a powerful and simple interface for integrating applications.\u00a0<\/span><\/p>\n<p><strong>Step 1: Design the Prompts<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">There are a few guidelines for designing and creating the prompts:<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Guide the ChatGPT model API on whether you would want the prompts in the form of instructions, examples, or a mix of both. Also if you want to use ChatGPT API for ranking a list or classify the items displayed, then you need to state that.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Provide appropriate ChatGPT API examples to help build the pattern. Ensure the examples are audited and proof-read multiple items<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Next is to control the top_p and temperature in the settings for ChatGPT API integration. Adjust it to a lower value for one response and higher for diverse responses.<\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">Refer document <\/span><a href=\"https:\/\/platform.openai.com\/docs\/guides\/completion\/prompt-design\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/platform.openai.com\/docs\/guides\/completion\/prompt-design<\/span><\/a><\/p>\n<p><strong>Step 2: Text Classification<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">Here are some of the best practices for classifying text in ChatGPT Public API:<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Decision on the implication and sentiment of the description or text &#8211; whether it is neutral, positive, or negative<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Suggested to use of plain, and simple language to easily understand and interpret<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">The description must be elaborated as much as possible, but removing additional words to ensure consistent performance<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">There must be the presence of sentiment labels in each of the instructions for easy judgment by the users\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Lastly, you must run several tests to check that the probability of your settings is calibrated correctly<\/span><\/li>\n<\/ol>\n<p><strong>Step 3: New idea generation<\/strong><\/p>\n<ol>\n<li><span style=\"font-weight: 400;\">Design the <a href=\"https:\/\/openai.com\/blog\/chatgpt\" target=\"_blank\" rel=\"noopener\">ChatGPT<\/a> API to generate new ideas or different versions of the input. It can be slogans, some character descriptions, business plans, or even story ideas.\u00a0<\/span><\/li>\n<li><span style=\"font-weight: 400;\">To ensure a quality response, include some examples in the prompt section and add them to the ChatGPT API server<\/span><\/li>\n<\/ol>\n<p><strong>Step 4: Devising ways to converse<\/strong><\/p>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">The ChatGPT API must be instructed on how to behave and respond to the instructions by providing the text explicitly<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">The ChatGPT API key needs to be provided with an identity through which it responds like an AI assistant or a chatbot<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Create a questions and answers sequence and then allow the Chatbot API token to pick up the patterns and use it for the return responses<\/span><\/li>\n<\/ol>\n<p><strong>Step 5: Introducing transformations<\/strong><\/p>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Develop the ChatGPT API to translate from one language to another, especially the languages with which the API is not well-conversed or familiar. You need to provide multiple examples to make the translation work<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Devise the adaptability of the ChatGPT API to convert texts into characters or emojis by entering the appropriate patterns. This method is called conversion<\/span><\/li>\n<\/ol>\n<p><strong>Step 6: Creating a summary<\/strong><\/p>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">If you want the ChatGPT API to share a summary about a topic then it is recommended to provide a paragraph with details on that topic. The API will then traverse through the topic and answer queries as per the questions being asked.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">For example, if a child asks about the planet Saturn. You can write \u201cSaturn is the sixth planet in the Solar system. After Jupiter, it is the second-largest planet. The unique feature of the planet is its ring system prominently visible and made of ice particles mainly. Saturn has 83 moons of which Titan is the largest and second-largest in the Solar system\u2026.\u201d<\/span><\/li>\n<\/ol>\n<p><strong>Step 7: Setting the completion tips<\/strong><\/p>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">The <a href=\"https:\/\/openai.com\/blog\/introducing-chatgpt-and-whisper-apis\" target=\"_blank\" rel=\"noopener\">ChatGPT<\/a> API limits need to be adjusted to check the completion of a response or statement\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">The temperature setting must be controlled to increase focus on a topic and end the response or keep it neutral to extend the boundary on the topic before the completion.\u00a0<\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">A sample code component for \u201cReact\u201d statements<\/span><\/p>\n<p><span style=\"font-weight: 400;\">import React from &#8216;react&#8217;;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const HeaderComponent = () =&gt; (<\/span><\/p>\n<p><strong>Step 8: Preparing factual responses<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">Train the ChatGPT API to provide realistic responses<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Do not train the API to read responses from entries like Wikipedia<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Prepare responses after researching various topics, websites, factual materials, etc., and feed them to the API for generating quality responses<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">For queries that are tough to answer or ready answer not available, train the API to respond as \u201cDont know\u201d<\/span><\/li>\n<\/ol>\n<h2><strong>How to use ChatGPT API for chat completion &#8211; step by step integration guide<\/strong><\/h2>\n<p><span style=\"font-weight: 400;\">The next important topic related to ChatGPT API is how to use ChatGPT API for chat completion. Let\u2019s now run through the steps, the examples, and the best practices and recommendations for using ChatGPT API for chats.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Using the chat option, the <a href=\"https:\/\/openai.com\/blog\/introducing-chatgpt-and-whisper-apis\" target=\"_blank\" rel=\"noopener\">ChatGPT API<\/a> can perform a wide variety of tasks like drafting an email, writing codes, displaying document links or references while responding to questions, providing tutorials, language translation, simulating characters for video games, conversations, and many more.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Let&#8217;s now focus on certain key points to remember on how to use ChatGPT API for chat completion<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">The design should be to ease the multi-turn conversations as well as single-turn without any type of conversations<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">The message parameter is the key input, containing an array of objects. The objects have content and role<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">The system message is used to determine the behavior, the user message is used to provide instructions, and the assistant message is used to record the previous responses<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">All related and relevant information must be shared in the form of conversations as the ChatGPT Get API key does not possess the memory of storing past requests.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">The conversations need to be shortened and adjusted as per the ChatGPT API endpoint and token limits<\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">Now let\u2019s look at how to create the format of the response.<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">A ChatGPT API example of extracting the reply to the assistant message is\u00a0<\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Response[&#8216;choices&#8217;][0][&#8216;message&#8217;][&#8216;content&#8217;].<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Next is to provide the different and probable values for the finish_reason. Every response must contain this particular parameter. The values which can be normally found in finish_reason are:<\/span><\/li>\n<\/ol>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">stop: ChatGPT API call returns the output of the entire model<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">length: limit, as set in the parameter, max_tokens for returning the model output, and due to the settings it returns the incomplete result<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">content_filter: a flag is set in the content_filter for omitting content<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">null: ChatGPT API response is incomplete or in progress<\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">The next important part is to manage tokens. Tokens are an answer to the question of how to call <a href=\"https:\/\/openai.com\/blog\/chatgpt\" target=\"_blank\" rel=\"noopener\">ChatGPT<\/a> API.<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">The models of the ChatGPT API can read chats in groups which are referred to as tokens<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">The token can be a string of characters or one word<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">The use of the number of tokens for ChatGPT API access to a particular sentence determines the cost of the API as the payment is done per token<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">The more you write the tokens, the more it takes time to call the API<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">It is important to remember that the total number of tokens must be less than the maximum limit of the model<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">While counting the tokens, you must consider both the input and output ones<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">You must check the total number of tokens used in the ChatGPT login screen and call through the usage field: <\/span><span style=\"font-weight: 400;\">response[&#8216;usage&#8217;][&#8216;total_tokens&#8217;]<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">If you do not want to go for an API call for counting tokens, then use the tiktoken Python library of OpenAI.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">In any message to the <a href=\"https:\/\/openai.com\/blog\/chatgpt\" target=\"_blank\" rel=\"noopener\">ChatGPT<\/a> API, the tokens are consumed by the content, the role of the user, and some additional fields which may be used for formatting the messages.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">If the conversation cannot fit in the threshold limit of the tokens, then it is recommended to reduce the text length. But while reducing length, ensure the knowledge part is not compromised<\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">Last but not least is how to provide instructions to the ChatGPT API model, which may vary from version to version.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Some models understand system messages while others understand the user messages better. It is advised to experiment with various approaches and modifications like using a specific format, leveraging explicit instructions, and providing logical guidance to the model to think before answering a response.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">When you access ChatGPT through API, then remember the significance of the values set for the temperature and the max tokens. If the temperature is set at a higher value, then the response will appear randomly. And if the temperature is set at a lower value, then the output is more relevant and focused.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In the case of max tokens, you need to set the length judiciously. Sometimes the response returned may be shrunk and not provide the complete message as desired by the user.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Refer documentation <\/span><a href=\"https:\/\/platform.openai.com\/docs\/guides\/chat\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/platform.openai.com\/docs\/guides\/chat<\/span><\/a><\/p>\n<h2><strong>ChatGPT API documentation references<\/strong><\/h2>\n<p>If you want to know the detailed description of the models, libraries, coding, and lot more, please check out the following ChatGPT API documentation references:<\/p>\n<p>1. For ChatGPT API overview, and key concepts like ChatGPT API model, prompts, and tokens,<br \/>\nrefer: <a href=\"https:\/\/platform.openai.com\/docs\/introduction\/overview\" target=\"_blank\" rel=\"noopener\">https:\/\/platform.openai.com\/docs\/introduction\/overview<\/a><br \/>\n2. For quickstart, ChatGPT API tutorial, refer <a href=\"https:\/\/platform.openai.com\/docs\/quickstart\" target=\"_blank\" rel=\"noopener\">https:\/\/platform.openai.com\/docs\/quickstart<\/a><br \/>\n3. For the list of libraries available for installation, please refer <a href=\"https:\/\/platform.openai.com\/docs\/libraries\" target=\"_blank\" rel=\"noopener\">https:\/\/platform.openai.com\/docs\/libraries<\/a><br \/>\n4. To learn details about the models, their capabilities and the price points, the ChatGPT API doc reference is <a href=\"https:\/\/platform.openai.com\/docs\/models\" target=\"_blank\" rel=\"noopener\">https:\/\/platform.openai.com\/docs\/models<\/a><br \/>\n5. The tutorial for building real ChatGPI API apps is available here <a href=\"https:\/\/platform.openai.com\/docs\/tutorials\" target=\"_blank\" rel=\"noopener\">https:\/\/platform.openai.com\/docs\/tutorials<\/a><br \/>\n6. The different legal policies of ChatGPT API can be referred to here <a href=\"https:\/\/openai.com\/policies\" target=\"_blank\" rel=\"noopener\">https:\/\/openai.com\/policies<\/a><br \/>\n7. The text completion guide is present in <a href=\"https:\/\/platform.openai.com\/docs\/guides\/completion\" target=\"_blank\" rel=\"noopener\">https:\/\/platform.openai.com\/docs\/guides\/completion<\/a><br \/>\n8. The chat completion guide is present at <a href=\"https:\/\/platform.openai.com\/docs\/guides\/chat\" target=\"_blank\" rel=\"noopener\">https:\/\/platform.openai.com\/docs\/guides\/chat<\/a><br \/>\n9. The image generation guide is present in <a href=\"https:\/\/platform.openai.com\/docs\/guides\/images\" target=\"_blank\" rel=\"noopener\">https:\/\/platform.openai.com\/docs\/guides\/images<\/a><br \/>\n10. The overview of the plugins in ChatGPT API is mentioned in <a href=\"https:\/\/platform.openai.com\/docs\/plugins\/introduction\" target=\"_blank\" rel=\"noopener\">https:\/\/platform.openai.com\/docs\/plugins\/introduction<\/a>, the tutorial for the plugins is at<br \/>\n<a href=\"https:\/\/platform.openai.com\/docs\/plugins\/getting-started\" target=\"_blank\" rel=\"noopener\">https:\/\/platform.openai.com\/docs\/plugins\/getting-started<\/a>, and the examples of plugins can be referred from https:\/\/platform.openai.com\/docs\/plugins\/examples<\/p>\n<h2><strong>How to use ChatGPT Python API?<\/strong><\/h2>\n<p><span style=\"font-weight: 400;\">Here are the steps on how to use ChatGPT Python API:<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">You need to create an account in OpenAI and sign in<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">You will find \u201cPersonal\u201d on the right-side top part where you have to click on \u201cView API Keys\u201d<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Click on the button \u201cCreate new secret key\u201d and once the key is generated copy it<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Install Open AI library in Python\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Import the library and store the key as generated for Python ChatGPT API integration<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Next using the JSON file, you need to instruct the API the activities it needs to perform and set the role too.<\/span><\/li>\n<\/ol>\n<p><b>Sample code:<\/b><\/p>\n<p><b>while<\/b><span style=\"font-weight: 400;\"> True:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0message <\/span><b>=<\/b><span style=\"font-weight: 400;\"> input(&#8220;User : &#8220;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><b>if<\/b><span style=\"font-weight: 400;\"> message:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0messages.append(<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{&#8220;role&#8221;: &#8220;user&#8221;, &#8220;content&#8221;: message},<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chat <\/span><b>=<\/b><span style=\"font-weight: 400;\"> openai.ChatCompletion.create(<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0model<\/span><b>=<\/b><span style=\"font-weight: 400;\">&#8220;gpt-3.5-turbo&#8221;, messages<\/span><b>=<\/b><span style=\"font-weight: 400;\">messages<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0)<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0reply <\/span><b>=<\/b><span style=\"font-weight: 400;\"> chat.choices[0].message.content<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0print(f&#8221;ChatGPT: {reply}&#8221;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0messages.append({&#8220;role&#8221;: &#8220;assistant&#8221;, &#8220;content&#8221;: reply})<\/span><\/p>\n<p style=\"text-align: center;\"><strong>Also Read:<\/strong> <a href=\"https:\/\/unremot.com\/blog\/how-to-use-spotify-api\/\">How to use Spotify API &#8211; a step-by-step integration guide<\/a><\/p>\n<h2><strong>How to use ChatGPT API nodejs?<\/strong><\/h2>\n<p><span style=\"font-weight: 400;\">The steps on how to use ChatGPT API nodejs are elaborated below<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">First is to create a new project in nodejs ChatGPT API<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Second is to generate a ChatGPT API key after logging into OpenAI<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">The API key needs to be assigned to an environment variable of the nodejs application<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Then implement the node.js application<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">The code needs to perform the following functions:<\/span>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">Import the dependencies<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">Perform asynchronous function<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">Set up and configure the <a href=\"https:\/\/openai.com\/blog\/introducing-chatgpt-and-whisper-apis\" target=\"_blank\" rel=\"noopener\">ChatGPT API<\/a> npm<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">Provision to store the chat history<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">Chat loop for continuous prompting user for input and generating the response<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">AI Model for response generation<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">Error handling<\/span><\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p><b>Sample Code:<\/b><\/p>\n<p><span style=\"font-weight: 400;\">const { Configuration, OpenAIApi } = require(&#8220;openai&#8221;);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const readlineSync = require(&#8220;readline-sync&#8221;);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">require(&#8220;dotenv&#8221;).config();<\/span><\/p>\n<p><span style=\"font-weight: 400;\">(async () =&gt; {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0const configuration = new Configuration({<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0apiKey: process.env.OPENAI_API_KEY,<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0});<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0const openai = new OpenAIApi(configuration);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0const history = [];<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0while (true) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0const user_input = readlineSync.question(&#8220;Your input: &#8220;);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0const messages = [];<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0for (const [input_text, completion_text] of history) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0messages.push({ role: &#8220;user&#8221;, content: input_text });<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0messages.push({ role: &#8220;assistant&#8221;, content: completion_text });<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0messages.push({ role: &#8220;user&#8221;, content: user_input });<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0try {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0const completion = await openai.createChatCompletion({<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0model: &#8220;gpt-3.5-turbo&#8221;,<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0messages: messages,<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0});<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0const completion_text = completion.data.choices[0].message.content;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0console.log(completion_text);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0history.push([user_input, completion_text]);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0const user_input_again = readlineSync.question(<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8220;\\nWould you like to continue the conversation? (Y\/N)&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (user_input_again.toUpperCase() === &#8220;N&#8221;) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} else if (user_input_again.toUpperCase() !== &#8220;Y&#8221;) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0console.log(&#8220;Invalid input. Please enter &#8216;Y&#8217; or &#8216;N&#8217;.&#8221;);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0} catch (error) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (error.response) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0console.log(error.response.status);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0console.log(error.response.data);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} else {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0console.log(error.message);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">})();<\/span><\/p>\n<h2><strong>How to use ChatGPT API c#?<\/strong><\/h2>\n<p><span style=\"font-weight: 400;\">Follow the below steps to learn how to use ChatGPT API c# for integration:<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">First, you need to install the OpenAI library<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Second, you need to create an account and log in to OpenAI<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Third, create a class OpenAIProxy for encapsulating the logic which will help to access ChatGPT c# APIs<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Fourth, create an implementation class called OpenAIProxy.cs<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Fifth, set up the API key in the application which will be used to access the ChatGPT API Model<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Finally, the ChatGPT model is used in the application that creates an infinite loop of user prompt and response generation.<\/span><\/li>\n<\/ol>\n<p style=\"text-align: center;\"><strong>Also Read: <a href=\"https:\/\/unremot.com\/blog\/what-is-dev-shop-how-to-find-the-best-dev-shop\/\">What is a dev shop and how to find the best dev shop?<\/a><\/strong><\/p>\n<h2><strong>How to use Azure ChatGPT API?<\/strong><\/h2>\n<p><span style=\"font-weight: 400;\">As the first step on how to use Azure ChatGPT API, you need to have an Azure subscription, access to Azure OpenAI, the latest version for Python and deployed Azure OpenAI service resource model<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Next is to configure the Azure environment and the OpenAI variables. The variables can be checked from the ChatGPT Azure API environment under \u201cKeys and Endpoint\u201d.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The third step is to define the input from the user and the logic that needs to be coded for the same.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The fourth step is to process the message from the user and display the content of the message.<\/span><\/p>\n<p><b>Sample code:<\/b><\/p>\n<p><span style=\"font-weight: 400;\">var msg = Console.ReadLine();<\/span><\/p>\n<p><span style=\"font-weight: 400;\">do<\/span><\/p>\n<p><span style=\"font-weight: 400;\">{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0var results = await chatOpenAI.SendChatMessage(msg);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0for each (var item in results)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0Console.WriteLine($&#8221;{item.Role}: {item.Content}&#8221;);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}<\/span><span style=\"font-weight: 400;\">\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0Console.WriteLine(&#8220;Next Prompt:&#8221;);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0msg = Console.ReadLine();<\/span><span style=\"font-weight: 400;\">\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">} while (msg != &#8220;bye&#8221;);<\/span><\/p>\n<p style=\"text-align: center;\"><strong>Also Read: <a href=\"https:\/\/unremot.com\/blog\/developers-to-know-intellectual-property-rights\/\">What Developers Need To Know About Intellectual Property Rights?<\/a><\/strong><\/p>\n<h2><strong>How to use ChatGPT API js?<\/strong><\/h2>\n<p><span style=\"font-weight: 400;\">The steps on how to use ChatGPT API js are as follows:<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Create a ChatGPT javascript API key after creating an account in OpenAI API<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Set up the javascript environment by creating a new file with the libraries and dependencies<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">After adding the key to the ChatGPT API, you need to send a request and receive the JSON response, to receive the extracted information<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Next, you need to display the response from the ChatGPT API to the user. You can have a timestamp, date, and emoticons added to the response as additional features.<\/span><\/li>\n<\/ol>\n<h2><strong>How to use ChatGPT API php?<\/strong><\/h2>\n<p><span style=\"font-weight: 400;\">Displaying the steps on how to use ChatGPT API php:<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Create an account in OpenAI and sign in to it<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Get the ChatGPT php API keys by clicking on the menu \u201cPersonal\u201d and clicking on \u201cView API keys\u201d<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Develop now the application using the <a href=\"https:\/\/openai.com\/blog\/introducing-chatgpt-and-whisper-apis\" target=\"_blank\" rel=\"noopener\">ChatGPT API<\/a><\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Select the library and deduce the codes\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Run the application<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">You need to define the input, process the message and receive the response<\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">Sample code:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">$<\/span><span style=\"font-weight: 400;\">curl<\/span> <span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">curl_init<\/span><span style=\"font-weight: 400;\">();<\/span><\/p>\n<p><span style=\"font-weight: 400;\">curl_setopt_array<\/span><span style=\"font-weight: 400;\">($<\/span><span style=\"font-weight: 400;\">curl<\/span><span style=\"font-weight: 400;\">,<\/span> <b>array<\/b><span style=\"font-weight: 400;\">(<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">CURLOPT_URL<\/span> <span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\">&gt; <\/span><span style=\"font-weight: 400;\">&#8216;https:\/\/api.openai.com\/v1\/completions&#8217;<\/span><span style=\"font-weight: 400;\">,<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">CURLOPT_RETURNTRANSFER<\/span> <span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\">&gt; <\/span><b>true<\/b><span style=\"font-weight: 400;\">,<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">CURLOPT_ENCODING<\/span> <span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\">&gt; <\/span><span style=\"font-weight: 400;\">&#8221;<\/span><span style=\"font-weight: 400;\">,<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">CURLOPT_MAXREDIRS<\/span> <span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\">&gt; <\/span><span style=\"font-weight: 400;\">10<\/span><span style=\"font-weight: 400;\">,<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">CURLOPT_TIMEOUT<\/span> <span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\">&gt; <\/span><span style=\"font-weight: 400;\">0<\/span><span style=\"font-weight: 400;\">,<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">CURLOPT_FOLLOWLOCATION<\/span> <span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\">&gt; <\/span><b>true<\/b><span style=\"font-weight: 400;\">,<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">CURLOPT_HTTP_VERSION<\/span> <span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\">&gt; <\/span><span style=\"font-weight: 400;\">CURL_HTTP_VERSION_1_1<\/span><span style=\"font-weight: 400;\">,<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">CURLOPT_CUSTOMREQUEST<\/span> <span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\">&gt; <\/span><span style=\"font-weight: 400;\">&#8216;POST&#8217;<\/span><span style=\"font-weight: 400;\">,<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">CURLOPT_POSTFIELDS<\/span> <span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\">&gt;<\/span><span style=\"font-weight: 400;\">&#8216;{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0&#8220;model&#8221;: &#8220;text-davinci-003&#8221;,<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0&#8220;prompt&#8221;: &#8220;Translate this into 1. French, 2. Hindi, 3. Spanish, 4.Japanese:\\n\\n1 What rooms do you have available?\\n\\n.&#8221;,<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0&#8220;temperature&#8221;: 0.3,<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0&#8220;max_tokens&#8221;: 100,<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0&#8220;top_p&#8221;: 1.0,<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0&#8220;frequency_penalty&#8221;: 0.0,<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0&#8220;presence_penalty&#8221;: 0.0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}&#8217;<\/span><span style=\"font-weight: 400;\">,<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">CURLOPT_HTTPHEADER<\/span> <span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\">&gt; <\/span><b>array<\/b><span style=\"font-weight: 400;\">(<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">&#8216;Authorization: Bearer sk-NRPZ9Ybx*****************L2mTVd8&#8217;<\/span><span style=\"font-weight: 400;\">,<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">&#8216;Content-Type: application\/json&#8217;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">),<\/span><\/p>\n<p><span style=\"font-weight: 400;\">));<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0<\/span><span style=\"font-weight: 400;\">$<\/span><span style=\"font-weight: 400;\">response<\/span> <span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">curl_exec<\/span><span style=\"font-weight: 400;\">($<\/span><span style=\"font-weight: 400;\">curl<\/span><span style=\"font-weight: 400;\">);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">curl_close<\/span><span style=\"font-weight: 400;\">($<\/span><span style=\"font-weight: 400;\">curl<\/span><span style=\"font-weight: 400;\">);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0<\/span><span style=\"font-weight: 400;\">echo<\/span> <span style=\"font-weight: 400;\">&#8220;&lt;pre&gt;&#8221;<\/span><span style=\"font-weight: 400;\">;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">print_r<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">json_decode<\/span><span style=\"font-weight: 400;\">($<\/span><span style=\"font-weight: 400;\">response<\/span><span style=\"font-weight: 400;\">));<\/span><\/p>\n<h2><strong>How to use ChatGPT API Java?<\/strong><\/h2>\n<p><span style=\"font-weight: 400;\">Just like the above sub-sections, the steps for how to use ChatGPT API java are quite simple.<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Create an account in OpenAI and sign in to it<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Generate a ChatGPT API key<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Go to Settings under the Organization menu and request for \u201cOrganization ID\u201d for ChatGPT Java API<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Create the files &#8211; FileHelper.java, Request.json, and ChatGPTAPIExample.java as part of the Java ChatGPT API integration<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Compile and run the application as per the run commands and check the response<\/span><\/li>\n<\/ol>\n<p><b>Sample code<\/b><\/p>\n<p><span style=\"font-weight: 400;\">import<\/span><span style=\"font-weight: 400;\"> java<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">io<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">BufferedReader<\/span><span style=\"font-weight: 400;\">;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">import<\/span><span style=\"font-weight: 400;\"> java<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">io<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">File<\/span><span style=\"font-weight: 400;\">;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">import<\/span><span style=\"font-weight: 400;\"> java<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">io<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">InputStreamReader<\/span><span style=\"font-weight: 400;\">;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">import<\/span><span style=\"font-weight: 400;\"> java<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">io<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">OutputStream<\/span><span style=\"font-weight: 400;\">;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">import<\/span><span style=\"font-weight: 400;\"> java<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">net<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">HttpURLConnection<\/span><span style=\"font-weight: 400;\">;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">import<\/span><span style=\"font-weight: 400;\"> java<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">net<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">URL<\/span><span style=\"font-weight: 400;\">;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">import<\/span><span style=\"font-weight: 400;\"> java<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">nio<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">charset<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">StandardCharsets<\/span><span style=\"font-weight: 400;\">;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">public<\/span> <span style=\"font-weight: 400;\">class<\/span> <span style=\"font-weight: 400;\">ChatGPTAPIExample<\/span> <span style=\"font-weight: 400;\">{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">public<\/span> <span style=\"font-weight: 400;\">static<\/span> <span style=\"font-weight: 400;\">void<\/span><span style=\"font-weight: 400;\"> listTokens<\/span><span style=\"font-weight: 400;\">()<\/span> <span style=\"font-weight: 400;\">{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">try<\/span> <span style=\"font-weight: 400;\">{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\/\/This API will fetch the models available.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">URL url <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">new<\/span><span style=\"font-weight: 400;\"> URL<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">&#8220;https:\/\/api.openai.com\/v1\/models&#8221;<\/span><span style=\"font-weight: 400;\">);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">HttpURLConnection<\/span><span style=\"font-weight: 400;\"> con <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">HttpURLConnection<\/span><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"> url<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">openConnection<\/span><span style=\"font-weight: 400;\">();<\/span><\/p>\n<p><span style=\"font-weight: 400;\">con<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">setRequestMethod<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">&#8220;GET&#8221;<\/span><span style=\"font-weight: 400;\">);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">con<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">setRequestProperty<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">&#8220;Content-Type&#8221;<\/span><span style=\"font-weight: 400;\">,<\/span> <span style=\"font-weight: 400;\">&#8220;application\/json&#8221;<\/span><span style=\"font-weight: 400;\">);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">con<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">setRequestProperty<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">&#8220;Accept&#8221;<\/span><span style=\"font-weight: 400;\">,<\/span> <span style=\"font-weight: 400;\">&#8220;application\/json&#8221;<\/span><span style=\"font-weight: 400;\">);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\/\/Make sure you put the right Organization key saved earlier.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">con<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">setRequestProperty<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">&#8220;OpenAI-Organization&#8221;<\/span><span style=\"font-weight: 400;\">,<\/span> <span style=\"font-weight: 400;\">&#8220;your-org-key&#8221;<\/span><span style=\"font-weight: 400;\">);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">con<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">setDoOutput<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">true<\/span><span style=\"font-weight: 400;\">);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\/\/Make sure you put the right API Key saved earlier.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">con<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">setRequestProperty<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">&#8220;Authorization&#8221;<\/span><span style=\"font-weight: 400;\">,<\/span> <span style=\"font-weight: 400;\">&#8220;Bearer your-api-key&#8221;<\/span><span style=\"font-weight: 400;\">);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">int<\/span><span style=\"font-weight: 400;\"> responseCode <\/span><span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\"> con<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">getResponseCode<\/span><span style=\"font-weight: 400;\">();<\/span><\/p>\n<p><span style=\"font-weight: 400;\">System<\/span><span style=\"font-weight: 400;\">.<\/span><i><span style=\"font-weight: 400;\">out<\/span><\/i><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">println<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">&#8220;Response Code : &#8220;<\/span> <span style=\"font-weight: 400;\">+<\/span><span style=\"font-weight: 400;\"> responseCode<\/span><span style=\"font-weight: 400;\">);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">BufferedReader<\/span> <span style=\"font-weight: 400;\">in<\/span> <span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">new<\/span> <span style=\"font-weight: 400;\">BufferedReader<\/span><span style=\"font-weight: 400;\">(<\/span><\/p>\n<p><span style=\"font-weight: 400;\">new<\/span> <span style=\"font-weight: 400;\">InputStreamReader<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">con<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">getInputStream<\/span><span style=\"font-weight: 400;\">()));<\/span><\/p>\n<p><span style=\"font-weight: 400;\">String<\/span><span style=\"font-weight: 400;\"> inputLine<\/span><span style=\"font-weight: 400;\">;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">StringBuffer<\/span><span style=\"font-weight: 400;\"> response <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">new<\/span> <span style=\"font-weight: 400;\">StringBuffer<\/span><span style=\"font-weight: 400;\">();<\/span><\/p>\n<p><span style=\"font-weight: 400;\">while<\/span> <span style=\"font-weight: 400;\">((<\/span><span style=\"font-weight: 400;\">inputLine <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">in<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">readLine<\/span><span style=\"font-weight: 400;\">())<\/span> <span style=\"font-weight: 400;\">!=<\/span> <span style=\"font-weight: 400;\">null<\/span><span style=\"font-weight: 400;\">)<\/span> <span style=\"font-weight: 400;\">{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">response<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">append<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">inputLine<\/span><span style=\"font-weight: 400;\">);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">in<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">close<\/span><span style=\"font-weight: 400;\">();<\/span><\/p>\n<p><span style=\"font-weight: 400;\">System<\/span><span style=\"font-weight: 400;\">.<\/span><i><span style=\"font-weight: 400;\">out<\/span><\/i><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">println<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">response<\/span><span style=\"font-weight: 400;\">);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span> <span style=\"font-weight: 400;\">catch<\/span> <span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">Exception<\/span><span style=\"font-weight: 400;\"> e<\/span><span style=\"font-weight: 400;\">)<\/span> <span style=\"font-weight: 400;\">{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">System<\/span><span style=\"font-weight: 400;\">.<\/span><i><span style=\"font-weight: 400;\">out<\/span><\/i><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">println<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">e<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">getMessage<\/span><span style=\"font-weight: 400;\">());<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">public<\/span> <span style=\"font-weight: 400;\">static<\/span> <span style=\"font-weight: 400;\">void<\/span><span style=\"font-weight: 400;\"> prompts<\/span><span style=\"font-weight: 400;\">()<\/span> <span style=\"font-weight: 400;\">{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">try<\/span> <span style=\"font-weight: 400;\">{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">URL url <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">new<\/span><span style=\"font-weight: 400;\"> URL<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">&#8220;https:\/\/api.openai.com\/v1\/completions&#8221;<\/span><span style=\"font-weight: 400;\">);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">HttpURLConnection<\/span><span style=\"font-weight: 400;\"> con <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">HttpURLConnection<\/span><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"> url<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">openConnection<\/span><span style=\"font-weight: 400;\">();<\/span><\/p>\n<p><span style=\"font-weight: 400;\">con<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">setRequestMethod<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">&#8220;POST&#8221;<\/span><span style=\"font-weight: 400;\">);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">con<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">setRequestProperty<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">&#8220;Content-Type&#8221;<\/span><span style=\"font-weight: 400;\">,<\/span> <span style=\"font-weight: 400;\">&#8220;application\/json&#8221;<\/span><span style=\"font-weight: 400;\">);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">con<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">setRequestProperty<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">&#8220;Accept&#8221;<\/span><span style=\"font-weight: 400;\">,<\/span> <span style=\"font-weight: 400;\">&#8220;application\/json&#8221;<\/span><span style=\"font-weight: 400;\">);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\/\/Make sure you put the right Organization key saved earlier.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">con<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">setRequestProperty<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">&#8220;OpenAI-Organization&#8221;<\/span><span style=\"font-weight: 400;\">,<\/span> <span style=\"font-weight: 400;\">&#8220;your-org-key&#8221;<\/span><span style=\"font-weight: 400;\">);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">con<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">setDoOutput<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">true<\/span><span style=\"font-weight: 400;\">);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\/\/Make sure you put the right API Key saved earlier.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">con<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">setRequestProperty<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">&#8220;Authorization&#8221;<\/span><span style=\"font-weight: 400;\">,<\/span> <span style=\"font-weight: 400;\">&#8220;Bearer your-api-key&#8221;<\/span><span style=\"font-weight: 400;\">);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\/\/Make sure to relace the path of the json file created earlier.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">String<\/span><span style=\"font-weight: 400;\"> jsonInputString <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">FileHelper<\/span><span style=\"font-weight: 400;\">.<\/span><i><span style=\"font-weight: 400;\">readLinesAsString<\/span><\/i><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">new<\/span> <span style=\"font-weight: 400;\">File<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">&#8220;C:\\\\yourpath\\\\request.json&#8221;<\/span><span style=\"font-weight: 400;\">));<\/span><\/p>\n<p><span style=\"font-weight: 400;\">try<\/span> <span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">OutputStream<\/span><span style=\"font-weight: 400;\"> os <\/span><span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\"> con<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">getOutputStream<\/span><span style=\"font-weight: 400;\">())<\/span> <span style=\"font-weight: 400;\">{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">byte<\/span><span style=\"font-weight: 400;\">[]<\/span><span style=\"font-weight: 400;\"> input <\/span><span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\"> jsonInputString<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">getBytes<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">StandardCharsets<\/span><span style=\"font-weight: 400;\">.<\/span><i><span style=\"font-weight: 400;\">UTF_8<\/span><\/i><span style=\"font-weight: 400;\">);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">os<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">write<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">input<\/span><span style=\"font-weight: 400;\">,<\/span> <span style=\"font-weight: 400;\">0<\/span><span style=\"font-weight: 400;\">,<\/span><span style=\"font-weight: 400;\"> input<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">length<\/span><span style=\"font-weight: 400;\">);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">int<\/span><span style=\"font-weight: 400;\"> responseCode <\/span><span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\"> con<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">getResponseCode<\/span><span style=\"font-weight: 400;\">();<\/span><\/p>\n<p><span style=\"font-weight: 400;\">System<\/span><span style=\"font-weight: 400;\">.<\/span><i><span style=\"font-weight: 400;\">out<\/span><\/i><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">println<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">&#8220;Response Code : &#8220;<\/span> <span style=\"font-weight: 400;\">+<\/span><span style=\"font-weight: 400;\"> responseCode<\/span><span style=\"font-weight: 400;\">);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">BufferedReader<\/span> <span style=\"font-weight: 400;\">in<\/span> <span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">new<\/span> <span style=\"font-weight: 400;\">BufferedReader<\/span><span style=\"font-weight: 400;\">(<\/span><\/p>\n<p><span style=\"font-weight: 400;\">new<\/span> <span style=\"font-weight: 400;\">InputStreamReader<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">con<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">getInputStream<\/span><span style=\"font-weight: 400;\">()));<\/span><\/p>\n<p><span style=\"font-weight: 400;\">String<\/span><span style=\"font-weight: 400;\"> inputLine<\/span><span style=\"font-weight: 400;\">;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">StringBuffer<\/span><span style=\"font-weight: 400;\"> response <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">new<\/span> <span style=\"font-weight: 400;\">StringBuffer<\/span><span style=\"font-weight: 400;\">();<\/span><\/p>\n<p><span style=\"font-weight: 400;\">while<\/span> <span style=\"font-weight: 400;\">((<\/span><span style=\"font-weight: 400;\">inputLine <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">in<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">readLine<\/span><span style=\"font-weight: 400;\">())<\/span> <span style=\"font-weight: 400;\">!=<\/span> <span style=\"font-weight: 400;\">null<\/span><span style=\"font-weight: 400;\">)<\/span> <span style=\"font-weight: 400;\">{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">response<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">append<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">inputLine<\/span><span style=\"font-weight: 400;\">);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">in<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">close<\/span><span style=\"font-weight: 400;\">();<\/span><\/p>\n<p><span style=\"font-weight: 400;\">System<\/span><span style=\"font-weight: 400;\">.<\/span><i><span style=\"font-weight: 400;\">out<\/span><\/i><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">println<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">response<\/span><span style=\"font-weight: 400;\">);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span> <span style=\"font-weight: 400;\">catch<\/span> <span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">Exception<\/span><span style=\"font-weight: 400;\"> e<\/span><span style=\"font-weight: 400;\">)<\/span> <span style=\"font-weight: 400;\">{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">System<\/span><span style=\"font-weight: 400;\">.<\/span><i><span style=\"font-weight: 400;\">out<\/span><\/i><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">println<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">e<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">getMessage<\/span><span style=\"font-weight: 400;\">());<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">public<\/span> <span style=\"font-weight: 400;\">static<\/span> <span style=\"font-weight: 400;\">void<\/span><span style=\"font-weight: 400;\"> main<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">String<\/span><span style=\"font-weight: 400;\">[]<\/span><span style=\"font-weight: 400;\"> args<\/span><span style=\"font-weight: 400;\">)<\/span> <span style=\"font-weight: 400;\">{<\/span><\/p>\n<p><i><span style=\"font-weight: 400;\">listTokens<\/span><\/i><span style=\"font-weight: 400;\">();<\/span><\/p>\n<p><i><span style=\"font-weight: 400;\">prompts<\/span><\/i><span style=\"font-weight: 400;\">();<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p style=\"text-align: center;\"><strong>Also read: <a href=\"https:\/\/unremot.com\/blog\/reduce-costs-of-software-development-outsourcing\/\">7 Ways to reduce the costs of software development outsourcing<\/a><\/strong><\/p>\n<h2><strong>How to use ChatGPT API Flutter?<\/strong><\/h2>\n<p>The prerequisites for using ChatGPT API with Flutter are the latest versions of Android Studio, Flutter, and Dart installed, and a basic understanding of Flutter development.<\/p>\n<p>Step 1: Open Android Studio and create a new Flutter project.<\/p>\n<p>Step 2: Edit the project name, Android and iOS language, and platform.<\/p>\n<p>Step 3: Generate the ChatGPT API key and add it to the environment.<\/p>\n<p>Step 4: Implement ChatGPT along with the necessary access and dependencies.<\/p>\n<p><b>Sample code:<\/b><\/p>\n<p><span style=\"font-weight: 400;\">dynamic saveChatHistory(<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0dynamic chatHistory,<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0dynamic newChat,<\/span><\/p>\n<p><span style=\"font-weight: 400;\">) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\/\/\/ MODIFY CODE ONLY BELOW THIS LINE<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\/\/ If chatHistory isn&#8217;t a list, make it a list and then add newChat<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0if (chatHistory is List) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0chatHistory.add(newChat);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0return chatHistory;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0} else {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0return [newChat];<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\/\/\/ MODIFY CODE ONLY ABOVE THIS LINE<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<h2><strong>ChatGPT API pricing<\/strong><\/h2>\n<p><span style=\"font-weight: 400;\">The ChatGPT API pricing is said to be 10 times cheaper than the existing models. The ChatGPT API cost is now USD 0.003 for 1000 tokens. Tokens are the series of messages along with the metadata that the ChatGPT Model consumes.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Along with the ChatGPT API price, one more thing that needs to be understood is that the enterprise data submitted via the ChatGPT API will not be leveraged for model training or any kind of improvements without the permission of the organization. Customers using Apps and services integrated with ChatGPT must be clear that they are interacting with a bot.<\/span><\/p>\n<h2><strong>Does ChatGPT have an API?<\/strong><\/h2>\n<p><span style=\"font-weight: 400;\">If you want to know if is there an API for <a href=\"https:\/\/openai.com\/blog\/chatgpt\" target=\"_blank\" rel=\"noopener\">ChatGPT<\/a>, the answer is Yes. The ChatGPT API release date initially was 30th November 2022 and the stable release was on 23rd March 2023. The API equips developers to generate responses that are personalized and human-like for any text input, even in the form of a chat.<\/span><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article will discuss how to use ChatGPT API. Let&#8217;s get started! Overview of ChatGPT API ChatGPT is an upcoming and quite popular chatbot utilizing cutting-edge technologies. It is now an important criterion to use ChatGPT API and integrate it with the existing applications in a company for better usage.\u00a0 In this article, we will [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":5136,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[76],"tags":[],"class_list":{"0":"post-5115","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-technology","8":"entry"},"_links":{"self":[{"href":"https:\/\/unremot.com\/blog\/wp-json\/wp\/v2\/posts\/5115","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unremot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unremot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unremot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unremot.com\/blog\/wp-json\/wp\/v2\/comments?post=5115"}],"version-history":[{"count":24,"href":"https:\/\/unremot.com\/blog\/wp-json\/wp\/v2\/posts\/5115\/revisions"}],"predecessor-version":[{"id":5153,"href":"https:\/\/unremot.com\/blog\/wp-json\/wp\/v2\/posts\/5115\/revisions\/5153"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/unremot.com\/blog\/wp-json\/wp\/v2\/media\/5136"}],"wp:attachment":[{"href":"https:\/\/unremot.com\/blog\/wp-json\/wp\/v2\/media?parent=5115"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unremot.com\/blog\/wp-json\/wp\/v2\/categories?post=5115"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unremot.com\/blog\/wp-json\/wp\/v2\/tags?post=5115"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}