# Client

The main class to interact with API.

|         **Attributes/Parameters**         |              **Methods**              |
| :---------------------------------------: | :-----------------------------------: |
|           [`api_key`](#api_key)           | [`get_ai_response`](#get_ai_response) |
|           [`version`](#version)           |       [`get_image`](#get_image)       |
| [`suppress_warnings`](#suppress_warnings) |        [`get_joke`](#get_joke)        |
|                                           |           [`close`](#close)           |

## Attributes

### `api_key`

This your API authentication key.

**Type:** [`str`](https://www.w3schools.com/python/python_strings.asp)

{% hint style="warning" %}
As of version 3, The API key is required to use the API. Get one from [here](https://api-info.pgamerx.com/register).
{% endhint %}

### `version`

The version of API to use. This defaults to `"4"`

**Type:** [`str`](https://www.w3schools.com/python/python_strings.asp)

### `suppress_warnings`

Determines if version or other warnings will be shown in console or not. Set this to `True` to stop warnings.

{% hint style="info" %}
[Warnings ](../brief/warnings)are usually printed on outdated versions of API.
{% endhint %}

**Type:** [`bool`](https://www.w3schools.com/python/python_strings.asp)

## Methods

### `get_ai_response`

Gets random AI response.

{% hint style="info" %}
This method takes version specific parameters. It is recommended to use version 4 to avoid timeout errors as version 3 AI endpoint was unstable.
{% endhint %}

{% tabs %}
{% tab title="Arguments (Version 4)" %}
These are parameters for _**version 4**_**.**

#### `message`

The message to which the response is required.

**Type**: [`str`](https://www.w3schools.com/python/python_strings.asp)

#### `plan` (Optional)

The plan to use for AI response.&#x20;

**Type:** [`str`](https://www.w3schools.com/python/python_strings.asp)

This must be one of from the [plans list](../../brief/lists#plans).

#### `language` (Optional)

The language of returned response. This defaults to `en`.&#x20;

**Type:** [`str`](https://www.w3schools.com/python/python_strings.asp)

#### `server` (Optional)

The server from which the response should be received. This defaults to `primary`. Set it to `backup` if the primary is down. Don't use `unstable` as it is quiet unstable.

**Type:** [`str`](https://www.w3schools.com/python/python_strings.asp)

#### `master` (Optional)

The developer's name. Used in responses. Defaults to `PGamerX` This is basically what bot will say on "Who is your creator?" or related questions.

**Type:** [`str`](https://www.w3schools.com/python/python_strings.asp)

#### `bot` (Optional)

The bot's name. This is used in responses. Defaults to `RSA`. This is basically what bot will say on "Who are you?" or "What is your name?" or related questions.

**Type:**[`str`](https://www.w3schools.com/python/python_strings.asp)

#### `uid` (Optional)

The unique ID. This is used to create a separate session. Read [Unique ID](../brief/unique-id) page for more info.&#x20;

**Type:** [`str`](https://www.w3schools.com/python/python_strings.asp)

{% hint style="info" %}
Above parameters are version 4 specific. If you're using version 3, See next tab.
{% endhint %}
{% endtab %}

{% tab title="Arguments (Version 3)" %}
Below arguments are specific to **version 3.**

#### `message`

The message to which the response is required.

**Type**: [`str`](https://www.w3schools.com/python/python_strings.asp)

#### `plan` (Optional)

The plan to use for AI response.&#x20;

**Type:** [`str`](https://www.w3schools.com/python/python_strings.asp)

This must be one of from the [plans list](../../brief/lists#plans).

#### `lang` (Optional)

The language of returned response. This defaults to `en`.&#x20;

**Type:** [`str`](https://www.w3schools.com/python/python_strings.asp)

#### **`type`** (Optional)

The server from which the response should be received. This defaults to `stable`. Don't use `unstable` as it is quiet unstable.

**Type:** [`str`](https://www.w3schools.com/python/python_strings.asp)

#### `dev_name` (Optional)

The developer's name. Used in responses. Defaults to `PGamerX` This is basically what bot will say on "Who is your creator?" or related questions.

**Type:** [`str`](https://www.w3schools.com/python/python_strings.asp)

#### `bot_name` (Optional)

The bot's name. This is used in responses. Defaults to `RSA`. This is basically what bot will say on "Who are you?" or "What is your name?" or related questions.

**Type:**[`str`](https://www.w3schools.com/python/python_strings.asp)

#### `unique_id` (Optional)

The unique ID. This is used to create a separate session. Read [Unique ID](../brief/unique-id) page for more info.&#x20;

**Type:** [`str`](https://www.w3schools.com/python/python_strings.asp)

{% hint style="info" %}
Above parameters are version 3 specific. If you're using version 4, See previous tab.
{% endhint %}
{% endtab %}

{% tab title="Returns" %}
The response as a AI response object.&#x20;

{% hint style="info" %}
To get the response message, Use `AIResponse.message`
{% endhint %}

**Type:** [`AIResponse`](../data-classes/airesponse)
{% endtab %}

{% tab title="Raises" %}
[`randomstuff.BadAPIKey`](../errors/autherror): The API key provided was invalid.

[`randomstuff.PlanNotAllowed`](../errors/autherror): The plan is not available on your account because you haven't bought it.

[`randomstuff.InvalidPlanError`](broken-reference): Provided plan was invalid

[`randomstuff.InvalidServerError`](broken-reference): The server is either not responding or invalid.
{% endtab %}
{% endtabs %}

### `get_image`

Gets a random image.

{% tabs %}
{% tab title="Arguments" %}
#### `type`(Optional)

The type of image. This is one of the types from [image types](../../brief/lists#image-types). Defaults to `any`.

**Type:** [`str`](https://www.w3schools.com/python/python_strings.asp)
{% endtab %}

{% tab title="Returns" %}
The image imgur link as a string.

**Type:** [`str`](https://www.w3schools.com/python/python_strings.asp)
{% endtab %}

{% tab title="Raises" %}
[`randomstuff.AuthError`](../errors/autherror): The API key provided was invalid.[`randomstuff.InvalidArgument`](../errors/argumenterror): The image type was not valid.
{% endtab %}
{% endtabs %}

### `get_joke`

Gets a random joke.

{% tabs %}
{% tab title="Arguments" %}
#### `type`(Optional)

The type of joke. This is one of the types from [joke types](../data-classes/joke). Defaults to `any`.

**Type:** [`str`](https://www.w3schools.com/python/python_strings.asp)
{% endtab %}

{% tab title="Returns" %}
The random joke as [`Joke`](../data-classes/joke) object.

**Type:** [`Joke`](../data-classes/joke)
{% endtab %}

{% tab title="Raises" %}
[`randomstuff.BadAPIKey`](../errors/autherror): The API key provided was invalid.

[`randomstuff.InvalidArgument`](../errors/argumenterror): The joke type was not valid.
{% endtab %}
{% endtabs %}

### `get_waifu`

Gets a random waifu/anime image URL.

{% hint style="info" %}
This is only available on version 4.
{% endhint %}

{% hint style="info" %}
This requires at least pro plan or higher to access.
{% endhint %}

{% tabs %}
{% tab title="Arguments" %}
#### `type`

The type of anime. Can be one from [Anime Types](../../brief/lists#anime-types)

**Type:** [`str`](https://www.w3schools.com/python/python_strings.asp)



#### `plan`

The plan to use. Can be one from [Plan Types](../../brief/lists#plans)

**Type:** [`str`](https://www.w3schools.com/python/python_strings.asp)


{% endtab %}

{% tab title="Returns" %}
The random anime as [`Waifu` ](../data-classes/waifu)object.

**Type:** [`Waifu`](../data-classes/waifu)
{% endtab %}

{% tab title="Raises" %}
[`randomstuff.BadAPIKey`](../errors/autherror): The API key provided was invalid.

[`randomstuff.InvalidArgument`](../errors/argumenterror): The waifu type was not valid.

[`randomstuff.PlanNotAllowed`](../errors/autherror/plannotallowed): The plan is not available on your API key.
{% endtab %}
{% endtabs %}

### `get_weather`

Gets the weather of provided city.

{% hint style="info" %}
This is only available on version 4.
{% endhint %}

{% tabs %}
{% tab title="Arguments" %}
#### `city`

The city of which weather is required.

**Type:** [`str`](https://www.w3schools.com/python/python_strings.asp)
{% endtab %}
{% endtabs %}

### `close`

Closes a session.

{% hint style="info" %}
It is always recommended to close a session after usage.
{% endhint %}

