# Crypto.com AI Agent Client

### Introduction

The Crypto.com AI Agent Client is a library designed to facilitate easy and efficient interactions with the Crypto.com AI Agent Service API. This client library provides methods to send queries and fetch responses from the Crypto.com AI Agent Service seamlessly, currently the library supports:&#x20;

* **TypeScript/JavaScript**
  * [npm page](https://www.npmjs.com/package/@crypto.com/ai-agent-client)
  * [Github](https://github.com/crypto-com/cdc-ai-agent-client-ts)
* **Python**
  * [Pypi page](https://pypi.org/project/crypto-com-ai-agent-client/)
  * [Github](https://github.com/crypto-com/cdc-ai-agent-client-py)

{% hint style="success" %}
The implementation of the AI Agent Client is open source and can be found in this [Github repository](https://github.com/crypto-com/developer-platform-sdk-examples/tree/main/ai/cryptocom-ai-agent-service). \
Developers can also refer to [Self-Hosting AI-Agent-Server](/outdated-contents/self-hosting-ai-agent-server.md) example to host it independently.
{% endhint %}

### Features

{% hint style="info" %}
**Currently in beta**: Expect frequent updates and potential changes in future releases.
{% endhint %}

* Simple and intuitive API for interacting with the Crypto.com AI Agent.
* Supports sending queries and receiving AI-generated responses.
* Configurable client instances tailored to your specific endpoint and security needs.
* Support networks: **Cronos zkEVM** and **Cronos EVM** mainnet and testnet.&#x20;

### Installation

{% tabs %}
{% tab title="TypeScript / JavaScript" %}
To install the package, run the following command in your project directory:

```
npm install @crypto.com/ai-agent-client
```

{% endtab %}

{% tab title="Python " %}
To install the package, run the following command:

```
pip install crypto-com-ai-agent-client
```

{% endtab %}
{% endtabs %}

### Usage

Here’s how you can use the Crypto.com AI Agent Client in your project:

#### Configuring the Client

{% tabs %}
{% tab title="TypeScript / JavaScript" %}

```javascript
import { createClient } from "@crypto.com/ai-agent-client";
import { QueryOptions } from "@crypto.com/ai-agent-client/dist/integrations/cdc-ai-agent.interfaces";

const OPEN_AI_API_KEY = "OPEN-AI-API-KEY";
const CHAIN_ID = 240; // 25 for Cronos EVM Mainnet, 338 for Cronos EVM Testnet, 388 for Cronos ZkEVM Mainnet, 240 for Cronos ZkEVM Testnet

const EXPLORER_KEY = "ZKEVM-TESTNET-API-KEY";

// Function to send a query and log the response
async function sendQuery(query: string) {
  // Create client params
  const queryOptions: QueryOptions = {
    openAI: {
      apiKey: OPEN_AI_API_KEY,
      model: "gpt-4-turbo",
    },
    chainId: CHAIN_ID,
    explorerKeys: {
      cronosMainnetKey: "YOUR-CRONOS-EVM-MAINNET-EXPLORER-KEY",
      cronosTestnetKey: "YOUR-CRONOS-EVM-TESTNET-EXPLORER-KEY",
      cronosZkEvmKey: "YOUR-CRONOS-zkEVM-MAINNET-EXPLORER-KEY",
      cronosZkEvmTestnetKey: EXPLORER_KEY,
    },
    context: [],
    // signerAppUrl: 'https://my-signer-app', // Refer to: https://github.com/crypto-com/cdc-ai-agent-signer-app
    // customRPC: 'https://rpc.vvs.finance,
  };
}
```

{% endtab %}

{% tab title="Python" %}

```python
from crypto_com_ai_agent_client import create_client

client = create_client({
    'openAI': {
        'apiKey': 'YOUR_OPEN_AI_API_KEY',
        'model': 'gpt-4o'  # Optional, defaults to 'gpt-4-turbo'
    },
    'chainId': 240,  # 25 for Cronos EVM Mainnet, 338 for Cronos EVM Testnet, 388 for Cronos ZkEVM Mainnet, 240 for Cronos ZkEVM Testnet
    'explorerKeys': {
        'cronosMainnetKey': 'CRONOS_MAINNET_API_KEY',
        'cronosTestnetKey': 'CRONOS_TESTNET_API_KEY',
        'cronosZkEvmKey': 'CRONOS_ZKEVM_API_KEY',
        'cronosZkEvmTestnetKey': 'CRONOS_ZKEVM_TESTNET_API_KEY'
    },
    'context': [],  # Optional
    'signerAppUrl': '',  # Optional, for example - https://my-signer-app
    'customRPC': ''  # Optional, if not provided, the default RPC for the chainId will be used
})
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
Here are the key details for:

**Cronos zkEVM**

* [Network config](https://docs-zkevm.cronos.org/for-developers/develop-smart-contracts-and-dapps#overview)
* [Explorer](https://docs-zkevm.cronos.org/for-developers/developer-tools/developer-portal-apis)[ API Key](https://docs-zkevm.cronos.org/for-developers/developer-tools/developer-portal-apis)

**Cronos EVM**

* [Network config](https://docs.cronos.org/cronos-chain-protocol/cronos-general-faq#what-is-the-chain-id-for-cronos-mainnet)
* [Explorer](https://docs.cronos.org/block-explorers/block-explorer-and-api-keys)[ API Key](https://docs.cronos.org/block-explorers/block-explorer-and-api-keys)
  {% endhint %}

Sending a Query

{% tabs %}
{% tab title="TypeScript/JavaScript" %}

```typescript
const sendQuery = async (query) => {
  try {
    const response = await client.agent.generateQuery(query);
    console.log('Crypto.com AI Agent Response:', response);
  } catch (error) {
    console.error('Error sending query:', error);
  }
};
```

{% endtab %}

{% tab title="Python" %}

```python
def send_query(query):
    try:
        response = client.agent.generate_query(query)
        print('Crypto.com AI Agent Response:', response)
    except Exception as e:
        print(f"Error sending query: {str(e)}")

send_query("What is the latest block?")
```

{% endtab %}
{% endtabs %}

### API

#### Client Methods

* `generate_query(query)`: Generates a query that is send to the Crypto.com AI Agent Service and returns a response.


---

# 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://ai-agent-sdk-docs.crypto.com/outdated-contents/crypto.com-ai-agent-client.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.
