Skip to content

Repository files navigation

ChatNio Python Library

The official Python library for the Chat Nio API

Features

  • Chat
  • Conversation
  • Quota
  • Subscription and Package

Installation

Install using pip

pip install --upgrade chatnio

And then import it

importchatnio

Usage

  • Authentication
chatnio.set_key("sk-...")
# or read from environment variablechatnio.set_key_from_env("CHATNIO_TOKEN")
# set custom api endpoint (default: https://api.chatnio.net)# chatnio.set_endpoint("https://example.com/api")# clear tokenchatnio.clear_key()
# get current tokenchatnio.get_token()
  • Chat
chat=awaitchatnio.new_chat()
asyncformessageinchat.ask("Hello, world!"):
print(message.message, end="")
  • Conversation
# list conversations (100 conversations max)forconversationinchatnio.list_conversations():
print(conversation.id, conversation.name)
# load conversationconversation=chatnio.load_conversation(42)
print(conversation)
formessageinconversation.messages:
print(message.role, message.content)
# delete conversationstate=chatnio.delete_conversation(42)
print(state)
  • Quota
# get quotaquota=chatnio.get_quota()
print(quota)
# buy quotastate=chatnio.buy_quota(1000)
print(state)
  • Subscription and Package
# get subscriptionsubscription=chatnio.get_subscription()
print(subscription.is_subscribed, subscription.expired)
# buy subscriptionstate=chatnio.buy_subscription(1, 1) # 1 month of basic planprint(state)
# get packagepackage=chatnio.get_package()
print(package)
  • Error

    chatnio.AuthenticationError

Test

To run the tests, you need to set the environment variable CHATNIO_TOKEN to your secret key.

export CHATNIO_TOKEN="sk-..."

Then run the tests

pytest

About

The official Python library for the Chat Nio API

Resources

Contributing

Stars

10 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages