# AiResource

Canonical page: https://docs.ovok.com/java-sdk/reference/ai-resource

```java
public final class AiResource
```

Calls the Ovok AI routes under `/ai`. Get it from [`Ovok.ai()`](/java-sdk/reference/ovok#ai).

## Methods [#methods]

### chat [#chat]

```java
public AiResource.ChatResource chat()
```

Returns the AI chat sessions and messages.

**Returns:** the chat resource

### translate [#translate]

```java
public JsonNode translate(Object body) throws IOException, InterruptedException
```

Translates text (`POST /ai/translation`).

**Parameters:**

- `body`: the translation request

**Returns:** the response body

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

```java
public JsonNode translate(
        Object body,
        RequestOptions options) throws IOException, InterruptedException
```

Translates text (`POST /ai/translation`).

**Parameters:**

- `body`: the translation request
- `options`: per-request options, such as the timeout

**Returns:** the response body

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

### fhirSearch [#fhirsearch]

```java
public JsonNode fhirSearch(Object body) throws IOException, InterruptedException
```

Turns a natural-language question into a FHIR search (`POST /ai/fhir/search`).

**Parameters:**

- `body`: the search request

**Returns:** the response body

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

```java
public JsonNode fhirSearch(
        Object body,
        RequestOptions options) throws IOException, InterruptedException
```

Turns a natural-language question into a FHIR search (`POST /ai/fhir/search`).

**Parameters:**

- `body`: the search request
- `options`: per-request options, such as the timeout

**Returns:** the response body

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

## AiResource.ChatResource [#airesourcechatresource]

```java
public static final class ChatResource
```

AI chat sessions and their messages. Get it from [`AiResource.chat()`](#chat).

### ChatResource.sessions [#chatresourcesessions]

```java
public AiResource.SessionsResource sessions()
```

Returns the chat sessions.

**Returns:** the sessions resource

### ChatResource.messages [#chatresourcemessages]

```java
public AiResource.MessagesResource messages()
```

Returns the chat messages.

**Returns:** the messages resource

## AiResource.SessionsResource [#airesourcesessionsresource]

```java
public static final class SessionsResource
```

AI chat sessions under `/ai/session`. Get it from [`ChatResource.sessions()`](#chatresourcesessions).

### SessionsResource.create [#sessionsresourcecreate]

```java
public JsonNode create(Object body) throws IOException, InterruptedException
```

Starts a chat session (`POST /ai/session`).

**Parameters:**

- `body`: the session to create

**Returns:** the response body

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

```java
public JsonNode create(Object body, RequestOptions options) throws IOException, InterruptedException
```

Starts a chat session (`POST /ai/session`).

**Parameters:**

- `body`: the session to create
- `options`: per-request options, such as the timeout

**Returns:** the response body

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

### SessionsResource.list [#sessionsresourcelist]

```java
public JsonNode list(Map<String, ?> parameters) throws IOException, InterruptedException
```

Lists chat sessions (`GET /ai/session`).

**Parameters:**

- `parameters`: query parameters

**Returns:** the response body

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

```java
public JsonNode list() throws IOException, InterruptedException
```

Lists chat sessions (`GET /ai/session`).

**Returns:** the response body

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

```java
public JsonNode list(
        Map<String, ?> parameters,
        RequestOptions options) throws IOException, InterruptedException
```

Lists chat sessions (`GET /ai/session`).

**Parameters:**

- `parameters`: query parameters
- `options`: per-request options, such as the timeout

**Returns:** the response body

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

### SessionsResource.retrieve [#sessionsresourceretrieve]

```java
public JsonNode retrieve(String sessionId) throws IOException, InterruptedException
```

Reads a chat session (`GET /ai/session/{id}`).

**Parameters:**

- `sessionId`: the session ID

**Returns:** the response body

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

```java
public JsonNode retrieve(
        String sessionId,
        Map<String, ?> parameters) throws IOException, InterruptedException
```

Reads a chat session (`GET /ai/session/{id}`).

**Parameters:**

- `sessionId`: the session ID
- `parameters`: query parameters

**Returns:** the response body

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

```java
public JsonNode retrieve(
        String sessionId,
        Map<String, ?> parameters,
        RequestOptions options) throws IOException, InterruptedException
```

Reads a chat session (`GET /ai/session/{id}`).

**Parameters:**

- `sessionId`: the session ID
- `parameters`: query parameters
- `options`: per-request options, such as the timeout

**Returns:** the response body

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

## AiResource.MessagesResource [#airesourcemessagesresource]

```java
public static final class MessagesResource
```

Messages in an AI chat session. Get it from [`ChatResource.messages()`](#chatresourcemessages).

### MessagesResource.list [#messagesresourcelist]

```java
public JsonNode list(
        String sessionId,
        Map<String, ?> parameters) throws IOException, InterruptedException
```

Lists a session's messages (`GET /ai/session/{id}/message`).

**Parameters:**

- `sessionId`: the session ID
- `parameters`: query parameters

**Returns:** the response body

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

```java
public JsonNode list(
        String sessionId,
        Map<String, ?> parameters,
        RequestOptions options) throws IOException, InterruptedException
```

Lists a session's messages (`GET /ai/session/{id}/message`).

**Parameters:**

- `sessionId`: the session ID
- `parameters`: query parameters
- `options`: per-request options, such as the timeout

**Returns:** the response body

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

### MessagesResource.send [#messagesresourcesend]

```java
public JsonNode send(String sessionId, Object body) throws IOException, InterruptedException
```

Sends a message to a session (`POST /ai/session/{id}/message`).

**Parameters:**

- `sessionId`: the session ID
- `body`: the message

**Returns:** the response body

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

```java
public JsonNode send(
        String sessionId,
        Object body,
        RequestOptions options) throws IOException, InterruptedException
```

Sends a message to a session (`POST /ai/session/{id}/message`).

**Parameters:**

- `sessionId`: the session ID
- `body`: the message
- `options`: per-request options, such as the timeout

**Returns:** the response body

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response
