> For the complete documentation index, see [llms.txt](https://rocket-networking.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://rocket-networking.gitbook.io/docs/api/ai.md).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
