# AI

The AI endpoint allows you to interact with the Rocket Networking AI service, powered by OpenAI. This endpoint allows you to make requests to generate AI-based responses using the GPT-3.5 Turbo model. You need to provide proper authentication using the `Authorization` header to access this endpoint.

### Endpoint Details

* **URL**: `https://apps.rocketnetworking.net/api/ai`
* **HTTP Method**: POST
* **Authentication**: Include your `serverId` in the `Authorization` header for all requests.

### Request

The AI endpoint accepts POST requests with the following parameters:

#### Request Body

The request body should include the following fields:

* **messages**: An array of message objects that form the conversation context. Each message object should have a `role` (either 'system', 'user', or 'assistant') and `content` containing the text of the message.
* **temperature**: A floating-point value controlling the randomness of the AI's response. Higher values (e.g., 0.8) make the response more random, while lower values (e.g., 0.2) make it more deterministic.

**Example Request Body**

```json
{
  "messages": [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "Tell me a joke."},
    {"role": "assistant", "content": "Why did the chicken cross the road?"}
  ],
  "temperature": 0.7,

}
```

### Response

Upon successful completion of the AI request, the API will return a JSON response with the following fields:

* **creditsUsed**: The number of RNet credits used for this AI request.
* **message**: The content of the AI-generated response.

**Example Response**

```json
{
  "creditsUsed": 54,
  "message": "Because it wanted to get to the other side!"
}
```

### Error Handling

* If the request lacks proper authentication (missing or invalid `Authorization` header), the API will respond with a `401 Unauthorized` status and an error message.
* In case of internal server errors, the API will respond with a `500 Internal Server Error` status.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://rocket-networking.gitbook.io/docs/api/ai.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
