Skip to main content
Version: v1.3.12

APIs

Create an API Key​

Overview​

You can create an application programming interface (API) key to obtain programmatic access to your Enterprise h2oGPTe account.

Instructions​

The following steps describe how to create an API Key:

  1. In the Enterprise h2oGPTe navigation menu, click APIs.
  2. Click + New API Key.
  3. (Optional) In the Key name box, enter a name for the API Key.
  4. (Optional) In the Collection list, select a Collection.
    note

    Specifying a Collection enables you to create a Collection-specific API Key by indicating the Collection you want to link it with. For more information, see Types of API keys.

  5. Click Generate new key.
    caution

    Do not share your API Key with others or expose it within the browser or other client-side code.

Create an API Key

info

Refer to the Python Client Guide v1.3.12 for detailed instructions on utilizing your API Key with the Enterprise h2oGPTe Python client.

Delete an API Key​

Overview​

Once an API Key is no longer in use, you can delete it.

caution

Deleting an API Key removes the API Key from the servers permanently. Once an API Key is deleted, there is no way to undo the action or recover the deleted API Key.

Instructions​

To delete an API Key, consider the following steps:

  1. In the Enterprise h2oGPTe navigation menu, click APIs.
  2. In the API Keys table, locate the checkbox corresponding to the API Key you wish to delete, then select it.
  3. Click Delete.
  4. In the Are you sure? card, click Delete.

Delete an API Key

Types of API Keys​

In Enterprise h2oGPTe there are two types of API Keys:

Global API Keys​

If a Collection is not specified when creating a new API Key, that key is considered to be a global API Key. Use global API Keys to grant full user impersonation and system-wide access to all of your work. Anyone with access to one of your global API Keys can create, delete, or interact with any of your past, current, and future Collections, Documents, Chats, and settings.

from h2ogpte import H2OGPTE

client = H2OGPTE(
address='https://',
api_key='sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
)

# Create a new collection
collection_id = client.create_collection(
name='Contracts',
description='Paper clip supply contracts',
)

# Create documents
# Note: Done for demonstration purposes only (not usually needed)
with open('dunder_mifflin.txt', 'w') as f:
f.write('There were 55 paper clips shipped, 22 to Scranton and 33 to Filmer.')

with open('initech.txt', 'w') as f:
f.write('David Brent did not sign any contract with Initech.')

# Upload documents
# Many file types are supported: text/image/audio documents and archives
with open('dunder_mifflin.txt', 'rb') as f:
dunder_mifflin = client.upload('Dunder Mifflin.txt', f)

with open('initech.txt', 'rb') as f:
initech = client.upload('IniTech.txt', f)

# Ingest documents (Creates previews, chunks and embeddings)
client.ingest_uploads(collection_id, [dunder_mifflin, initech])

# Create a chat session
chat_session_id = client.create_chat_session(collection_id)

# Query the collection
with client.connect(chat_session_id) as session:
reply = session.query(
'How many paper clips were shipped to Scranton?',
timeout=60,
)
print(reply.content)

reply = session.query(
'Did David Brent co-sign the contract with Initech?',
timeout=60,
)
print(reply.content)

# Summarize each document
documents = client.list_documents_in_collection(collection_id, offset=0, limit=99)
for doc in documents:
summary = client.summarize_document(
document_id=doc.id,
timeout=60,
)
print(summary.content)

Collection-specific API Keys​

Use Collection-specific API Keys to grant external access to only Chat with a specified Collection and make related API calls to it. Collection-specific API keys do not allow other API calls, such as creation, deletion, or access to other Collections or Chats.

from h2ogpte import H2OGPTE

client = H2OGPTE(
address='https://',
api_key='sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
)

# Automatically connects to the collection from the
# collection-specific API key
chat_session_id = client.create_chat_session_on_default_collection()

# Query the collection
with client.connect(chat_session_id) as session:
reply = session.query(
'How many paper clips were shipped to Scranton?',
timeout=60,
)
print(reply.content)

reply = session.query(
'Did David Brent co-sign the contract with Initech?',
timeout=60,
)
print(reply.content)

# Summarize each document
default_collection = client.get_default_collection()
documents = client.list_documents_in_collection(default_collection.id, offset=0, limit=99)
for doc in documents:
summary = client.summarize_document(
document_id=doc.id,
timeout=60,
)
print(summary.content)

Feedback