> For the complete documentation index, see [llms.txt](https://docs.coherent.global/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.coherent.global/integrations/openai.md).

# OpenAI

Spark is already your best way to codify your business logic and integrate it into your systems. It powers web portals and iPhone apps, cloud-scale modeling and simulation. Spark has solved the problems of translating business expertise into IT-consumable forms.

Generative AI, like [ChatGPT](https://chatgpt.com/) and [Gemini](https://gemini.google.com/), is great at language tasks and reasoning. However, numerical tasks and calculations can be unreliable. By combining Generative AI with quantitative tools and models we can unlock much more business value. And nothing *excels* at deploying those tools quite like Spark.

While Spark can be integrated into any of the large language models being developed, [OpenAI’s custom GPTs](https://openai.com/index/introducing-gpts/) provide an easy way to start to experiment and develop solutions in this space. The steps couldn’t be easier:

<details>

<summary>Prerequisites</summary>

* You have created a Spark service.
* You have at least a ChatGPT Plus subscription. Please see [Pricing](https://openai.com/chatgpt/pricing/) for more information.

</details>

## Setup a ChatGPT integration

1. Go to the [API Tester](/navigation/api-tester.md#integration) tab and copy the [API Tester](/navigation/api-tester.md#code-snippets) for *OpenAPI*.
2. In ChatGPT, click *Explore GPTs* and then go to *My GPTs*.
3. Click on **Create a GPT** then click on **Configure.**
4. Name your GPT and optionally add a description or custom instructions. Then click **Create new action.**
5. Paste your code snippet from Spark into the *Schema* field.
6. In the bottom right corner click the **Format** button. This will help to resolve discrepancies between ChatGPT's accepted schema versus the Code Snippet in YAML format.
7. For authentication:
   1. If you are performing quick integration testing, you can use [Authorization - Bearer token](/spark-apis/authorization-bearer-token.md) in *Authentication*.
   2. Alternatively, for more secure integrations, you can [#secure-the-integration-using-oauth2](#secure-the-integration-using-oauth2 "mention"):
      1. Create the OAuth2 Authorization Code Grant described below in [#secure-the-integration-using-oauth2](#secure-the-integration-using-oauth2 "mention").
      2. In the *Authentication* section, click on the settings wheel and select *OAuth2*.
      3. Provide the values for the *Client ID*, *Client Secret,* `authorization_endpoint`, `token_endpoint`.
      4. In the *Scope* field, enter `openid email profile offline_access` and click **Save**.
   3. Click on the **Test** button, then click **Sign In** to authenticate with your tenant.
   4. After a successful login, you will be redirected back to ChatGPT.
8. Click on your newly created GPT, go to Actions, and click the **Test** button.
9. Chat with your bot! Iterate on the prompts, Spark service, or even add additional services until you adjust to the desired behavior. The conversation is powerful enough to manage multiple executions against the Spark service, for example in conducting a comparison between different options.

## **Secure the integration using OAuth2**

1. Complete the initial steps for [Client Credentials grant (OAuth 2.0)](/identity-and-access-management/client-credentials/client-credentials-grant-oauth-2.0.md) [Client Credentials grant (OAuth 2.0)](/identity-and-access-management/client-credentials/client-credentials-grant-oauth-2.0.md#create-client) to create a separate client for ChatGPT. For this application, Ensure that *Standard flow enabled* is set to `On`.
2. Follow the steps to:
   1. [Client Credentials grant (OAuth 2.0)](/identity-and-access-management/client-credentials/client-credentials-grant-oauth-2.0.md#create-client-mappers).
   2. [Client Credentials grant (OAuth 2.0)](/identity-and-access-management/client-credentials/client-credentials-grant-oauth-2.0.md#create-the-credential).
   3. [Client Credentials grant (OAuth 2.0)](/identity-and-access-management/client-credentials/client-credentials-grant-oauth-2.0.md#assign-client-credentials-to-a-spark-folder).
3. In the *Login Settings* page, add the following *Redirect URIs* and then click **Save**.
   1. `https://chatgpt.com/*`
   2. `https://chat.openai.com/*`
4. Copy the *Client ID*.
5. Click the *Credentials* tab and copy the *Client Secret*.
6. In the left pane, click on *Realm Settings*, then scroll to the *Endpoints* section and click on *Open ID Endpoint Configuration*.
7. Copy the values for `authorization_endpoint` and `token_endpoint`.
