Skip to main content
Version: v1.4.9

Create an API Key

Overview​

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

Create an API Key

Instructions​

The following steps describe how to create an API Key:

  1. In the main Enterprise h2oGPTe navigation menu, click Settings.
  2. Click the + New API Key button.
  3. Optional: In the Key name field, enter a name for the API Key.
  4. Optional: You can optionally create a Collection-specific API Key by specifying a Collection to associate the new API Key with. For more information, see Types of API keys.
  5. Click the Generate new key button.
    caution

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

info

For more information on using your API key with the Enterprise h2oGPTe python client, see Python Client Guide.

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.

import os
from h2ogpte import H2OGPTE

client = H2OGPTE(
address='https://h2ogpte.genai.h2o.ai',
api_key='<API_KEY>')
)

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

# Upload documents
with open('/path/to/dunder_mifflin.pdf', 'rb') as f:
dunder_mifflin = client.upload('Dunder Mifflin.pdf', f)
with open('/path/to/wernham_hogg.pdf', 'rb') as f:
initech = client.upload('Wernham Hogg.pdf', f)

# Ingest Documents
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=10
)
print(reply.content)

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

Collection-specific API Keys​

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

note

API Keys can be bound to one Collection, in which case they can only be used for that Collection. You can start Chat sessions without specifying which Collection to use because the one it was created for will be used by default.

import os
from h2ogpte import H2OGPTE

client = H2OGPTE(
address='https://h2ogpte.genai.h2o.ai',
api_key=<API_KEY>)
)

# 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=10
)
print(reply.content)

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

Feedback