# Introduction

Generate asynchronous conversation endpoints for the OpenAI ChatGPT API

The [OffloadGPT API](https://rapidapi.com/microdeploy/api/offloadgpt) is a server-side API client that manages OpenAI ChatGPT API requests.

## How it works

OffloadGPT is an asynchronous API that stores ChatGPT responses on generated permalinks **without the need to wait the OpenAI API response**.

It saves the chat status of every request in order to easily retrieve the conversation or continue it.

The API offers support for the following features:

* Delegates API requests and relieves your server load from busy scripts.
* Instantly generates custom endpoint permalinks for each ChatGPT request.
* Parallel execution of multiple requests without compromising your server load.
* Full compatibility with the official [OpenAI Chat Completion](https://platform.openai.com/docs/api-reference/chat/create) parameters.
* Private and Public access to share conversations with others or ensure chat privacy.
* Real-time storing of Streaming and Asynchronous API responses.
* Notifies request finalization to external webhook URLs with the full processed data.
* Concatenates messages from previous responses using the `from_status_url` param.

## Want to jump right in?

Feeling like an eager beaver? Jump in to the quick start docs and get making your first request:

{% content-ref url="/pages/3P9loQ8Vw0ygg3lXYoCG" %}
[Quick Start](/quick-start)
{% endcontent-ref %}

## Want to deep dive?

Dive a little deeper and start exploring our API reference to get an idea of everything that's possible with the API:

{% content-ref url="/pages/IIv4LlUHzO9kKIX0Z8dz" %}
[API Reference](/reference/api-reference)
{% endcontent-ref %}


# Quick Start

The OffloadGPT API works in combination of the RapidAPI platform and the OpenAI Chat Completion API.

## Get your API keys

Your API requests are authenticated using API keys in the request headers. Any request that doesn't include an API key will return an error.

You can generate an API key from your [RapidAPI Developer Dashboard](https://rapidapi.com/developer/dashboard) at any time.

After that, you need to subscribe to the [OffloadGPT API](https://rapidapi.com/microdeploy/api/offloadgpt) in order to make requests. Just for testing purposes, there is a **free subscription plan** allowing 1000 requests per month.

In addition, you will need an [OpenAI API key](https://platform.openai.com/account/api-keys) for the internal request to the Chat Completion API.

{% hint style="info" %}
Your OpenAI API Key is used only for the OpenAI API call and **will never be saved, shared or published**. The OpenAI API Key is deleted in memory after the OpenAI API request is performed, avoiding to show it in logs or output debug.
{% endhint %}

{% hint style="info" %}
OpenAI allows you to establish limits on the use of its APIs, so it is highly recommended to enable [API usage limits](https://platform.openai.com/account/billing/limits) to prevent cases of loss or theft of keys.
{% endhint %}

## Make your first request

To make your first request, send an authenticated request to the `stream-chatgpt` endpoint. This will create a new generated endpoint that will store the ChatGPT API response.

Take a look at how you might call this method using any programming language or via `cURL`:

{% tabs %}
{% tab title="cURL" %}

```
curl --request POST \
	--url https://offloadgpt.p.rapidapi.com/v1/stream-chatgpt \
	--header 'content-type: application/json' \
	--header 'X-RapidAPI-Host: offloadgpt.p.rapidapi.com' \
	--header 'X-RapidAPI-Key: <REQUIRED>' \
	--header 'X-OpenAI-API-Key: <REQUIRED>' \
	--data '{
    "messages": [
        {
            "role": "system",
            "content": "You are an assistant of an online store selling hardware and I do not want you to talk about anything other than my products"
        },
        {
            "role": "user",
            "content": "Can you resume the pros and cons of the Soundcore by Anker Space Q45 Adaptive Active Noise Cancelling Headphones?"
        }
    ]
}'
```

{% endtab %}

{% tab title="Node" %}

```javascript
const http = require('https');

const options = {
	method: 'POST',
	hostname: 'offloadgpt.p.rapidapi.com',
	port: null,
	path: '/v1/stream-chatgpt',
	headers: {
		'content-type': 'application/json',
		'X-RapidAPI-Host': 'offloadgpt.p.rapidapi.com',
		'X-OpenAI-API-Key': '<REQUIRED>',
		'X-RapidAPI-Key': '<REQUIRED>'
	}
};

const req = http.request(options, function (res) {
	const chunks = [];

	res.on('data', function (chunk) {
		chunks.push(chunk);
	});

	res.on('end', function () {
		const body = Buffer.concat(chunks);
		console.log(body.toString());
	});
});

req.write(JSON.stringify({
  messages: [
    {
      role: 'system',
      content: 'You are an assistant of an online store selling hardware and I do not want you to talk about anything other than my products'
    },
    {
      role: 'user',
      content: 'Can you resume the pros and cons of the Soundcore by Anker Space Q45 Adaptive Active Noise Cancelling Headphones?'
    }
  ]
}));
req.end();
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://offloadgpt.p.rapidapi.com/v1/stream-chatgpt"

payload = { "messages": [
		{
			"role": "system",
			"content": "You are an assistant of an online store selling hardware and I do not want you to talk about anything other than my products"
		},
		{
			"role": "user",
			"content": "Can you resume the pros and cons of the Soundcore by Anker Space Q45 Adaptive Active Noise Cancelling Headphones?"
		}
	] }
headers = {
	"content-type": "application/json",
	"X-OpenAI-API-Key": "<REQUIRED>",
	"X-RapidAPI-Key": "<REQUIRED>",
	"X-RapidAPI-Host": "offloadgpt.p.rapidapi.com"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, [
	CURLOPT_URL => "https://offloadgpt.p.rapidapi.com/v1/stream-chatgpt",
	CURLOPT_RETURNTRANSFER => true,
	CURLOPT_ENCODING => "",
	CURLOPT_MAXREDIRS => 10,
	CURLOPT_TIMEOUT => 30,
	CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
	CURLOPT_CUSTOMREQUEST => "POST",
	CURLOPT_POSTFIELDS => json_encode([
		'messages' => [
				[
					'role' => 'system',
					'content' => 'You are an assistant of an online store selling hardware and I do not want you to talk about anything other than my products'
				],
				[
					'role' => 'user',
					'content' => 'Can you resume the pros and cons of the Soundcore by Anker Space Q45 Adaptive Active Noise Cancelling Headphones?'
				]
		]
	]),
	CURLOPT_HTTPHEADER => [
		"X-OpenAI-API-Key: <REQUIRED>",
		"X-RapidAPI-Host: offloadgpt.p.rapidapi.com",
		"X-RapidAPI-Key: <REQUIRED>",
		"content-type: application/json"
	],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
	echo "cURL Error #:" . $err;
} else {
	echo $response;
}
```

{% endtab %}

{% tab title="Javascript" %}

```javascript
const data = JSON.stringify({
	messages: [
		{
			role: 'system',
			content: 'You are an assistant of an online store selling hardware and I do not want you to talk about anything other than my products'
		},
		{
			role: 'user',
			content: 'Can you resume the pros and cons of the Soundcore by Anker Space Q45 Adaptive Active Noise Cancelling Headphones?'
		}
	]
});

const xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener('readystatechange', function () {
	if (this.readyState === this.DONE) {
		console.log(this.responseText);
	}
});

xhr.open('POST', 'https://offloadgpt.p.rapidapi.com/v1/stream-chatgpt');
xhr.setRequestHeader('content-type', 'application/json');
xhr.setRequestHeader('X-OpenAI-API-Key', '<REQUIRED>');
xhr.setRequestHeader('X-RapidAPI-Key', '<REQUIRED>');
xhr.setRequestHeader('X-RapidAPI-Host', 'offloadgpt.p.rapidapi.com');

xhr.send(data);
```

{% endtab %}
{% endtabs %}

## Check the results

If all goes well the expected HTTP response code is `200` , serving the content in JSON format as stated from the `application/json` header Content-Type.&#x20;

This is an example of a valid response:

```json
{
    "status": "success",
    "created_at": 1685617626,
    "conversation_id": "24b94bef-d2a6-4faa-bb20-1429e846c9d3",
    "README": "The `stream_events_url` endpoint below streams data sent by the ChatGPT API. Open it to receive incoming messages.",
    "authorization": {
        "access": "public"
    },
    "endpoints": {
        "status_url": "https://offloadgpt.microdeploy.com/1/r/pub/2023/06/01/11/07/06/24b94bef-d2a6-4faa-bb20-1429e846c9d3.json",
        "stream_events_url": "https://offloadgpt.microdeploy.com/1/r/pub/2023/06/01/11/07/06/24b94bef-d2a6-4faa-bb20-1429e846c9d3.txt",
        "stop_url": "https://offloadgpt.microdeploy.com/1/r/pub/2023/06/01/11/07/06/24b94bef-d2a6-4faa-bb20-1429e846c9d3/stop"
    }
}
```

Next, the first property to check is `status`, where the string `success` informs us that everything went well and the request has been sent to the OpenAI API.

We continue at the `endpoints` property and its subproperty `stream_events_url`. This value is intended to provide an URL where the response is sent in [text/event-stream](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#event_stream_format) format, allowing to create an text stream to the browser using [Javascript server-Sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events).

You can see an example of use of this stream API in this [demo project](https://github.com/pauiglesias/offload-chatgpt-streaming-demo).

Another important endpoint property is `status_url`, an URL intented to show the request status, informing if the request is **still waiting** the OpenAI ChatGPT response, an **error** has occurred or the **request is completed** and the response is available. In addition to the streaming endpoint, this `status_url` method also provides the response as it is generated.


# Server Events

(pending section, here will be examples of use)

```javascript

let html = '';
const eventSource = new EventSource(url);

eventSource.onmessage = function(e) {

	if (!e || !e.data) {
		onMessageEnd();
		return;
	}

	if (e.data == "[DONE]") {
		onMessageEnd();
		return;
	}

	const messageItem = parseEventData(e.data);
	if (!messageItem) {
		return;
	}
	
	const choice = 	messageItem.choices[0];
	let txt = choice.delta.content;
	
	if (null === txt || undefined === txt) {
		return;
	}
	
	txt = '' + txt;
	if ('' !== txt) {
		html += txt;
		theContentDiv.innerHTML = txt;
	}

	if (choice.finish_reason) {
		onMessageEnd();
	}
}

eventSource.onerror = function(e) {
	console.log(e);
	onMessageEnd();
}

function parseEventData(data) {

	let obj = null;

	try {

		obj = JSON.parse(data);
		if (!obj || !obj.choices) {
			return false;
		}

	} catch(e) {
		return false;
	}

	return obj;
}

function onMessageEnd() {
	/* Code for finalized message */
}

```


# API Reference

## Stream ChatGPT

Performs a managed ChatGPT API request to create an **streaming endpoint**.

{% content-ref url="/pages/PfNkXjbfyO8JOmLmv1Yc" %}
[stream-chatgpt endpoint](/reference/api-reference/stream-chatgpt-endpoint)
{% endcontent-ref %}

## Async ChatGPT

Performs a managed ChatGPT API request creating a **status endpoint** to track the response.

{% content-ref url="/pages/JzBq3OMd86SuGsJ09bjt" %}
[async-chatgpt endpoint](/reference/api-reference/async-chatgpt-endpoint)
{% endcontent-ref %}


# stream-chatgpt endpoint

Performs a managed ChatGPT API request to create an streaming endpoint.

Performs an [OpenAI Chat Completion](https://platform.openai.com/docs/api-reference/chat/create) request generating custom endpoints in order to display the response status and send the stream output in [text/event-stream](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#event_stream_format) format.

This endpoint is designed for sending **streaming data**. If this is not the case, it is recommended to use the  [async-chagpt endpoint](/reference/api-reference/async-chatgpt-endpoint).

The only required parameter -besides headers- is the `messages` parameter. All other parameters refer to the default values of the Chat Completion API.

## Request for a Stream ChatGPT endpoint&#x20;

## Generates streaming and asynchronous endpoints for chat responses.

<mark style="color:green;">`POST`</mark> `https://offloadgpt.p.rapidapi.com/v1/stream-chatgpt`

#### Headers

| Name                                               | Type   | Description                 |
| -------------------------------------------------- | ------ | --------------------------- |
| Content-Type                                       | String | `application/json`          |
| X-OpenAI-API-Key<mark style="color:red;">\*</mark> | String | \<Your OpenAI API key>      |
| X-RapidAPI-Key<mark style="color:red;">\*</mark>   | String | \<Your RapidAPI key>        |
| X-RapidAPI-Host<mark style="color:red;">\*</mark>  | String | `offloadgpt.p.rapidapi.com` |

#### Request Body

| Name                                       | Type            | Description                                                                                                                                                                                                                      |
| ------------------------------------------ | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| access                                     | string          | Privacy of the generated endpoints: `public` to be available for anyone, or `private` to access only using a generated Bearer Token. Default is `public`.                                                                        |
| timeout                                    | Number          | The timeout of the request in seconds. Default value is 90 seconds. Max timeout allowed is 90 seconds.                                                                                                                           |
| connect\_timeout                           | Number          | The timeout to stablish connection with the OpenAI API. Default value is 5 seconds. Max connection timeout allowed is 10 seconds.                                                                                                |
| from\_status\_url                          | String          | The Url of a previously generated `status_url`. This allows to concatenate the previous messages with the new one sent in the current request.                                                                                   |
| from\_bearer\_token                        | String          | In the case of setting a value to the `from_status_url` argument, if this URL is private then it is necessary to provide its associated `bearer_token` generated on the same request.                                            |
| conversation\_id                           | String          | If provided, any other conversation derived from this one will keep this conversation identifier. If not provided, a default id will be generated in [UUID format](https://en.wikipedia.org/wiki/Universally_unique_identifier). |
| webhook\_url                               | String          | A external URL to send, using the POST method, with all the information processed. There is only one parameter called `response` containing a JSON with the same information of the final `status_url` response.                 |
| model                                      | String          | Refers to the [model parameter](https://platform.openai.com/docs/api-reference/chat/create#chat/create-model) of the OpenAI Chat Completion API. If omitted, the default value is `gpt-3.5-turbo`.                               |
| messages<mark style="color:red;">\*</mark> | Array           | Refers to the [messages parameter](https://platform.openai.com/docs/api-reference/chat/create#chat/create-messages) of the OpenAI Chat Completion API. This is the only one required parameter.                                  |
| temperature                                | Number          | Refers to the [temperature parameter](https://platform.openai.com/docs/api-reference/chat/create#chat/create-temperature) of the OpenAI Chat Completion API. Defaults to 1.                                                      |
| top\_p                                     | Number          | Refers to the [top\_p parameter](https://platform.openai.com/docs/api-reference/chat/create#chat/create-top_p) of the OpenAI Chat Completion API. Defaults to 1.                                                                 |
| n                                          | Integer         | Refers to the [n parameter](https://platform.openai.com/docs/api-reference/chat/create#chat/create-top_p) of the OpenAI Chat Completion API. Defaults to 1.                                                                      |
| max\_tokens                                | Integer         | Refers to the [max\_tokens parameter](https://platform.openai.com/docs/api-reference/chat/create#chat/create-max_tokens) of the OpenAI Chat Completion API. Defaults to inf.                                                     |
| stop                                       | String or Array | Refers to the [stop parameter](https://platform.openai.com/docs/api-reference/chat/create#chat/create-stop) of the OpenAI Chat Completion API. Defaults to null.                                                                 |
| presence\_penalty                          | Number          | Refers to the [presence\_penalty parameter](https://platform.openai.com/docs/api-reference/chat/create#chat/create-presence_penalty) of the OpenAI Chat Completion API. Defaults to 0.                                           |
| frequency\_penalty                         | Number          | Refers to the [frequency\_penalty parameter](https://platform.openai.com/docs/api-reference/chat/create#chat/create-frequency_penalty) of the OpenAI Chat Completion API. Defaults to 0.                                         |
| logit\_bias                                | Map             | Refers to the [logit\_bias parameter](https://platform.openai.com/docs/api-reference/chat/create#chat/create-logit_bias) of the OpenAI Chat Completion API. Defaults to null.                                                    |
| user                                       | String          | Refers to the [user parameter](https://platform.openai.com/docs/api-reference/chat/create#chat/create-user) of the OpenAI Chat Completion API. Defaults to null.                                                                 |
| from\_max\_length                          | Number          | In the case of setting a value to the `from_status_url` argument, here you can restrict the number of characters from the last response of the previous messages.                                                                |

{% tabs %}
{% tab title="200 Endpoints successfully created" %}

```json
{
    "status": "success",
    "created_at": 1685617626,
    "conversation_id": "24b94bef-d2a6-4faa-bb20-1429e846c9d3",
    "README": "The `stream_events_url` endpoint below streams data sent by the ChatGPT API. Open it to receive incoming messages.",
    "authorization": {
        "access": "public"
    },
    "endpoints": {
        "status_url": "https://api.offloadgpt.com/1/r/pub/2023/06/01/11/07/06/24b94bef-d2a6-4faa-bb20-1429e846c9d3.json",
        "stream_events_url": "https://api.offloadgpt.com/1/r/pub/2023/06/01/11/07/06/24b94bef-d2a6-4faa-bb20-1429e846c9d3.txt",
        "stop_url": "https://api.offloadgpt.com/1/r/pub/2023/06/01/11/07/06/24b94bef-d2a6-4faa-bb20-1429e846c9d3/stop"
    }
}
```

{% endtab %}

{% tab title="401 Permission denied" %}

{% endtab %}
{% endtabs %}

## Response from the Stream ChatGPT endpoint&#x20;

For a successful request, the response will look as follows, having a `success` status:

```json
{
    "status": "success",
    "created_at": 1685617626,
    "conversation_id": "24b94bef-d2a6-4faa-bb20-1429e846c9d3",
    "README": "The `stream_events_url` endpoint below streams data sent by the ChatGPT API. Open it to receive incoming messages.",
    "authorization": {
        "access": "public"
    },
    "endpoints": {
        "status_url": "https://offloadgpt.microdeploy.com/1/r/pub/2023/06/01/11/07/06/24b94bef-d2a6-4faa-bb20-1429e846c9d3.json",
        "stream_events_url": "https://offloadgpt.microdeploy.com/1/r/pub/2023/06/01/11/07/06/24b94bef-d2a6-4faa-bb20-1429e846c9d3.txt",
        "stop_url": "https://offloadgpt.microdeploy.com/1/r/pub/2023/06/01/11/07/06/24b94bef-d2a6-4faa-bb20-1429e846c9d3/stop"
    }
}
```

We can see other properties such as `created_at`, the `conversation_id` (filled from the parameters or generated if missing), and the generated `endpoints` property.

{% hint style="info" %}
Note that this response has been created with the **`public`** value of the `access` argument, as specified in the property `authorization.access`.

This means that the resulting endpoints are **publicly available via GET requests**, and can be accessed by anyone even when navigating from a web browser.
{% endhint %}

### Response for private access requests&#x20;

For **private** access requests, the response would look as follows:

```json
{
    "status": "success",
    "created_at": 1685686261,
    "conversation_id": "633249b8-cee5-4636-ae71-5ed45624ac93",
    "README": "The `stream_events_url` endpoint below streams data sent by the ChatGPT API. Open it to receive incoming messages.",
    "authorization": {
        "access": "private",
        "bearer_token": "718862c1382b2ffbb445f6c1abec79b2",
        "stream_url_arg": "stream_token=2d1fe9502cd65b84dc90577f322d0300"
    },
    "endpoints": {
        "status_url": "https://offloadgpt.microdeploy.com/1/r/priv/2023/06/02/06/11/01/633249b8-cee5-4636-ae71-5ed45624ac93.json",
        "stream_events_url": "https://offloadgpt.microdeploy.com/1/r/priv/2023/06/02/06/11/01/633249b8-cee5-4636-ae71-5ed45624ac93.txt",
        "stop_url": "https://offloadgpt.microdeploy.com/1/r/priv/2023/06/02/06/11/01/633249b8-cee5-4636-ae71-5ed45624ac93/stop"
    }
}
```

Here we can see the following changes from the `authorization` property:

* The value of `access` is now `private`.
* It provides a `bearer_token` property.
* Additionally there is a `stream_url_arg` property.

In private requests, the generated endpoints can be accessed via GET requests using this header:

```
Authorization: Bearer <bearer_token>
```

In case you are using the `stream_events_url` from the Javascript EventSource object -which does not allow to add headers- you can grant access adding the `stream_url_arg` property to the `stream_events_url` endpoint:

```
https://offloadgpt.microdeploy.com/1/r/priv/...5ed45624ac93.txt?<stream_url_arg>
```

{% hint style="info" %}
In the same way, if you are chaining conversations using the `from_status_url` parameter, and the referenced conversation has private access, then you need to stablish the **`from_bearer_token`** parameter using the previous `bearer_token` value, ensuring to continue from a private request (even if the new request is public).
{% endhint %}

### Stopping active requests using the stop\_url endpoint

While the request is active and has not finished, you can stop the streaming flow of data and terminate the request using the **`stop_url`** endpoint.

It works as the same way as the other endpoints, so it is publicly accesible in case of public access, and needs the `Authorization: Bearer` for private access.

{% hint style="info" %}
After the request has finished and the OpenAI API response has been processed, this endpoint no longer has any effect and returns a `405` status code.
{% endhint %}


# async-chatgpt endpoint

Performs a managed ChatGPT API request creating a status endpoint.

Performs an [OpenAI Chat Completion](https://platform.openai.com/docs/api-reference/chat/create) request generating a custom endpoints in order to store and display the final response data.

This endpoint is designed for storing final request data. If you need **streaming capabilities**, it is recommended to use the [stream-chatgpt endpoint](/reference/api-reference/stream-chatgpt-endpoint).

The only required parameter -besides headers- is the `messages` parameter. All other parameters refer to the default values of the Chat Completion API.

## Request for a Async ChatGPT endpoint&#x20;

## Generates an asynchronous endpoint to store the final chat response.

<mark style="color:green;">`POST`</mark> `https://offloadgpt.p.rapidapi.com/v1/async-chatgpt`

#### Headers

| Name                                               | Type   | Description                 |
| -------------------------------------------------- | ------ | --------------------------- |
| Content-Type                                       | String | `application/json`          |
| X-OpenAI-API-Key<mark style="color:red;">\*</mark> | String | \<Your OpenAI API key>      |
| X-RapidAPI-Key<mark style="color:red;">\*</mark>   | String | \<Your RapidAPI key>        |
| X-RapidAPI-Host<mark style="color:red;">\*</mark>  | String | `offloadgpt.p.rapidapi.com` |

#### Request Body

| Name                                       | Type            | Description                                                                                                                                                                                                                      |
| ------------------------------------------ | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| access                                     | string          | Privacy of the generated endpoints: `public` to be available for anyone, or `private` to access only using a generated Bearer Token. Default is `public`.                                                                        |
| timeout                                    | Number          | The timeout of the request in seconds. Default value is 90 seconds. Max timeout allowed is 90 seconds.                                                                                                                           |
| connect\_timeout                           | Number          | The timeout to stablish connection with the OpenAI API. Default value is 5 seconds. Max connection timeout allowed is 10 seconds.                                                                                                |
| from\_status\_url                          | String          | The Url of a previously generated `status_url`. This allows to concatenate the previous messages with the new one sent in the current request.                                                                                   |
| from\_bearer\_token                        | String          | In the case of setting a value to the `from_status_url` argument, if this URL is private then it is necessary to provide its associated `bearer_token` generated on the same request.                                            |
| conversation\_id                           | String          | If provided, any other conversation derived from this one will keep this conversation identifier. If not provided, a default id will be generated in [uuid format](https://en.wikipedia.org/wiki/Universally_unique_identifier). |
| webhook\_url                               | String          | A external URL to send, using the POST method, with all the information processed. There is only one parameter called `response` containing a JSON with the same information of the final `status_url` response.                 |
| model                                      | String          | Refers to the [model parameter](https://platform.openai.com/docs/api-reference/chat/create#chat/create-model) of the OpenAI Chat Completion API. If omitted, the default value is `gpt-3.5-turbo`.                               |
| messages<mark style="color:red;">\*</mark> | Array           | Refers to the [messages parameter](https://platform.openai.com/docs/api-reference/chat/create#chat/create-messages) of the OpenAI Chat Completion API. This is the only one required parameter.                                  |
| temperature                                | Number          | Refers to the [temperature parameter](https://platform.openai.com/docs/api-reference/chat/create#chat/create-temperature) of the OpenAI Chat Completion API. Defaults to 1.                                                      |
| top\_p                                     | Number          | Refers to the [top\_p parameter](https://platform.openai.com/docs/api-reference/chat/create#chat/create-top_p) of the OpenAI Chat Completion API. Defaults to 1.                                                                 |
| n                                          | Integer         | Refers to the [n parameter](https://platform.openai.com/docs/api-reference/chat/create#chat/create-top_p) of the OpenAI Chat Completion API. Defaults to 1.                                                                      |
| max\_tokens                                | Integer         | Refers to the [max\_tokens parameter](https://platform.openai.com/docs/api-reference/chat/create#chat/create-max_tokens) of the OpenAI Chat Completion API. Defaults to inf.                                                     |
| stop                                       | String or Array | Refers to the [stop parameter](https://platform.openai.com/docs/api-reference/chat/create#chat/create-stop) of the OpenAI Chat Completion API. Defaults to null.                                                                 |
| presence\_penalty                          | Number          | Refers to the [presence\_penalty parameter](https://platform.openai.com/docs/api-reference/chat/create#chat/create-presence_penalty) of the OpenAI Chat Completion API. Defaults to 0.                                           |
| frequency\_penalty                         | Number          | Refers to the [frequency\_penalty parameter](https://platform.openai.com/docs/api-reference/chat/create#chat/create-frequency_penalty) of the OpenAI Chat Completion API. Defaults to 0.                                         |
| logit\_bias                                | Map             | Refers to the [logit\_bias parameter](https://platform.openai.com/docs/api-reference/chat/create#chat/create-logit_bias) of the OpenAI Chat Completion API. Defaults to null.                                                    |
| user                                       | String          | Refers to the [user parameter](https://platform.openai.com/docs/api-reference/chat/create#chat/create-user) of the OpenAI Chat Completion API. Defaults to null.                                                                 |
| from\_max\_length                          | Number          | In the case of setting a value to the `from_status_url` argument, here you can restrict the number of characters from the last response of the previous messages.                                                                |

{% tabs %}
{% tab title="200 Endpoints successfully created" %}

```json
{
    "status": "success",
    "created_at": 1685617626,
    "conversation_id": "24b94bef-d2a6-4faa-bb20-1429e846c9d3",
    "README": "The `stream_events_url` endpoint below streams data sent by the ChatGPT API. Open it to receive incoming messages.",
    "authorization": {
        "access": "public"
    },
    "endpoints": {
        "status_url": "https://api.offloadgpt.com/1/r/pub/2023/06/01/11/07/06/24b94bef-d2a6-4faa-bb20-1429e846c9d3.json",
        "stream_events_url": "https://api.offloadgpt.com/1/r/pub/2023/06/01/11/07/06/24b94bef-d2a6-4faa-bb20-1429e846c9d3.txt",
        "stop_url": "https://api.offloadgpt.com/1/r/pub/2023/06/01/11/07/06/24b94bef-d2a6-4faa-bb20-1429e846c9d3/stop"
    }
}
```

{% endtab %}

{% tab title="401 Permission denied" %}

{% endtab %}
{% endtabs %}

## Response from the Async ChatGPT endpoint&#x20;

For a successful request, the response will look as follows, having a `success` status:

```json
{
    "status": "success",
    "created_at": 1685695773,
    "conversation_id": "b7c4669e-40d4-4d16-bd83-bb34511db8a1",
    "README": "The `status_url` endpoint below continuously updates with data sent by the ChatGPT API. Load it to check for new data.",
    "authorization": {
        "access": "public"
    },
    "endpoints": {
        "status_url": "https://offloadgpt.microdeploy.com/1/r/pub/2023/06/02/08/49/33/b7c4669e-40d4-4d16-bd83-bb34511db8a1.json",
        "stop_url": "https://offloadgpt.microdeploy.com/1/r/pub/2023/06/02/08/49/33/b7c4669e-40d4-4d16-bd83-bb34511db8a1/stop"
    }
}
```

We can see other properties such as `created_at`, the `conversation_id` (filled from the parameters or generated if missing), and the generated `endpoints` property.

{% hint style="info" %}
Note that this response has been created with the **`public`** value of the `access` argument, as specified in the property `authorization.access`.

This means that the resulting endpoints are **publicly available via GET requests**, and can be accessed by anyone even when navigating from a web browser.
{% endhint %}

### Response for private access requests&#x20;

For **private** access requests, the response would look as follows:

```json
{
    "status": "success",
    "created_at": 1685695812,
    "conversation_id": "c23780e2-2fc5-4b83-b5bc-5297f47d5360",
    "README": "The `status_url` endpoint below continuously updates with data sent by the ChatGPT API. Load it to check for new data.",
    "authorization": {
        "access": "private",
        "bearer_token": "ad7b1834232536e9c59cb141b5fabe61"
    },
    "endpoints": {
        "status_url": "https://offloadgpt.microdeploy.com/2/r/priv/2023/06/02/08/50/12/c23780e2-2fc5-4b83-b5bc-5297f47d5360.json",
        "stop_url": "https://offloadgpt.microdeploy.com/2/r/priv/2023/06/02/08/50/12/c23780e2-2fc5-4b83-b5bc-5297f47d5360/stop"
    }
}
```

Here we can see the following changes from the `authorization` property:

* The value of `access` is now `private`.
* It provides a `bearer_token` property.

In private requests, the generated endpoints can be accessed via GET requests using this header:

```
Authorization: Bearer <bearer_token>
```

{% hint style="info" %}
In the same way, if you are chaining conversations using the `from_status_url` parameter, and the referenced conversation has private access, then you need to stablish the **`from_bearer_token`** parameter using the previous `bearer_token` value, ensuring to continue from a private request (even if the new request is public).
{% endhint %}

### Stopping active requests using the stop\_url endpoint

While the request is active and has not finished, you can stop and terminate the request using the **`stop_url`** endpoint.

It works as the same way as the other endpoints, so it is publicly accesible in case of public access, and needs the `Authorization: Bearer` for private access.

{% hint style="info" %}
After the request has finished and the OpenAI API response has been processed, this endpoint no longer has any effect and returns a `405` status code.
{% endhint %}


# Status URL endpoints

The generated Status URL endpoints contain the final request response.

A typical response from `async-chatgpt` endpoint could be something like this:

```json
{
    "status": "success",
    "created_at": 1685638041,
    "conversation_id": "154dff1d-a1b1-4270-bbbc-66b9a5700a12",
    "README": "The `status_url` endpoint below continuously updates with data sent by the ChatGPT API. Load it to check for new data.",
    "authorization": {
        "access": "public"
    },
    "endpoints": {
        "status_url": "https://offloadgpt.microdeploy.com/2/r/pub/2023/06/01/16/47/21/154dff1d-a1b1-4270-bbbc-66b9a5700a12.json",
        "stop_url": "https://offloadgpt.microdeploy.com/2/r/pub/2023/06/01/16/47/21/154dff1d-a1b1-4270-bbbc-66b9a5700a12/stop"
    }
}
```

The `endpoints.status_url` contains an URL that stores the current request status.&#x20;

Performing a GET request, the response is a JSON like this:

{% code fullWidth="false" %}

```json
{
    "status": "done",
    "created_at": 1685638041,
    "conversation_id": "154dff1d-a1b1-4270-bbbc-66b9a5700a12",
    "README": "This endpoint has completed the collection of data sent by the ChatGPT API and will not receive any further updates.",
    "endpoints": {
        "status_url": "https://offloadgpt.microdeploy.com/2/r/pub/2023/06/01/16/47/21/154dff1d-a1b1-4270-bbbc-66b9a5700a12.json",
        "response_raw_url": "https://offloadgpt.microdeploy.com/2/r/pub/2023/06/01/16/47/21/154dff1d-a1b1-4270-bbbc-66b9a5700a12.raw"
    },
    "request": {
        "endpoint": "/v1/async-chatgpt",
        "request_at": 1685638041,
        "finished_at": 1685638064,
        "processed_at": 1685638066,
        "request_time": 22.625,
        "total_time": 24.684
    },
    "options": {
        "timeout": 90,
        "connect_timeout": 5
    },
    "parameters": {
        "model": "gpt-3.5-turbo",
        "messages": [
            {
                "role": "system",
                "content": "You are an assistant of an online store selling hardware and I do not want you to talk about anything other than my products"
            },
            {
                "role": "user",
                "content": "Can you resume the pros and cons of the Soundcore by Anker Space Q45 Adaptive Active Noise Cancelling Headphones?"
            }
        ]
    },
    "response": {
        "status_code": 200,
        "protocol": "HTTP/2",
        "headers": {
            "date": "Thu, 01 Jun 2023 16:47:44 GMT",
            "content-type": "application/json",
            "content-length": "1816",
            "access-control-allow-origin": "*",
            "cache-control": "no-cache, must-revalidate",
            "openai-model": "gpt-3.5-turbo-0301",
            "openai-organization": "user-jix50wyfs2vbwg0bvxpgiixs",
            "openai-processing-ms": "22746",
            "openai-version": "2020-10-01",
            "strict-transport-security": "max-age=15724800; includeSubDomains",
            "x-ratelimit-limit-requests": "3500",
            "x-ratelimit-limit-tokens": "90000",
            "x-ratelimit-remaining-requests": "3499",
            "x-ratelimit-remaining-tokens": "89922",
            "x-ratelimit-reset-requests": "17ms",
            "x-ratelimit-reset-tokens": "52ms",
            "x-request-id": "e6d4fe690de1fb379cea0489902a64e3",
            "cf-cache-status": "DYNAMIC",
            "server": "cloudflare",
            "cf-ray": "7d08f01f3d7e3af4-IAD",
            "alt-svc": "h3=\":443\"; ma=86400"
        },
        "body": {
            "id": "chatcmpl-7MfkHkQbwGPbR7d54c1JwUuxHLe7Y",
            "object": "chat.completion",
            "created": 1685638041,
            "model": "gpt-3.5-turbo-0301",
            "usage": {
                "prompt_tokens": 62,
                "completion_tokens": 287,
                "total_tokens": 349
            },
            "choices": [
                {
                    "message": {
                        "role": "assistant",
                        "content": "Certainly, as an assistant of an online store, I can provide you with the technical specifications and pros of the Soundcore by Anker Space Q45 Adaptive Active Noise Cancelling Headphones:\n\nPros:\n- The headphones feature a hybrid active noise cancellation technology that uses both feedforward and feedback microphones to provide effective noise reduction.\n- The Soundcore Q45 headphones have a long battery life of up to 40 hours, allowing you to use them for extended periods without needing to recharge.\n- The headphones are also equipped with fast charging capabilities, which allow you to get up to four hours of playback time with just five minutes of charging.\n- They are lightweight, comfortable to wear and adjustable, making them suitable for long listening sessions.\n- The headphones have a built-in microphone for making phone calls and come with a 3.5 mm audio cable for wired listening.\n- The ear cups feature touch controls for easy access to playback, volume, and noise cancellation settings.\n- They have received positive reviews from customers, with many praising the sound quality and noise-canceling capabilities.\n\nCons:\n- The Soundcore Q45 headphones do not fold flat or come with a carrying case, which may make them less portable compared to some other options.\n- Some users have reported connectivity issues with devices like laptops and tablets, which may require troubleshooting.\n- The noise-cancelling feature may not be as effective compared to some high-end noise-canceling headphones."
                    },
                    "finish_reason": "stop",
                    "index": 0
                }
            ]
        }
    }
}
```

{% endcode %}

This structure is almost the same for both `stream-chagpt` and `async-chatgpt` endpoints:

#### status

*String* - One of the following values:

* `pending` The request has not yet been sent.
* `posting` The request has been sent but no response is expected yet.
* `waiting` Response in progress (async-chatgpt endpoint only).
* `streaming` Response data being transmitted (stream-chatgpt endpoint only).
* `done` Request finished and full data is available (final status).
* `error` A timeout or any API error response (final status).
* `stop` Terminated by a stop request invocation (final status).

#### created\_at

*Integer* - Timestamp of request creation

#### conversation\_id

*String* - Passed as a request parameter or generated if missing as a [UUID format](https://en.wikipedia.org/wiki/Universally_unique_identifier).

#### endpoints

*Object* - Contains the permalinks for the current generated endpoints.

#### endpoints / status\_url

*URL* - The current Status URL document.

#### endpoints / stream\_events\_url

*URL* - The URL gerated for streaming data (stream-chatgpt endpoint only).

#### endpoints / from\_status\_url

*URL* - The Status URL of the previous request (if passed as a parameter argument).

#### endpoints / response\_raw\_url

*URL* - Full raw response data including response headers.

#### request

*Object* - Information about the current request, such as the endpoint, start timestamp or and time elapsed in each stage.

#### options

*Object* - Parameters exclusive to this API (and not part of the OpenAI Chat Completion API), such `timeout` or `connect_timeout`.

#### parameters

*Object* - The parameters used for the OpenAI Chat Completion API request.

#### response

*Object* - The data related to the OpenAI Chat Completion API response.

#### response / status\_code

*Integer* - The HTTP response code from OpenAI Chat Completion API.

#### response / protocol

*String* - The protocol of the response, e.g. `HTTP/2`

#### response / headers

*Object* - All headers present in the response without additions.

#### response / body

*Object* - The original OpenAI Chat Completion response data in JSON format.


