h2oGPTe REST API: OpenAPI specification file
Overview​
The h2oGPTe OpenAPI specification file outlines the structure and functionality of the h2oGPTe REST API, detailing available endpoints, request and response formats, and authentication requirements.
-
OpenAPI specification: Access the specification in YAML format:
-
Interactive documentation: Explore the API through an interactive interface, complete with live endpoint examples:
Using the OpenAPI specification file for the h2oGPTe REST API, we have generated SDKs in multiple programming languages to help you quickly integrate with the API. Below are the available SDKs:
- Python SDK - Download Python SDK
- JavaScript SDK - Download JavaScript SDK
- Go SDK - Download Go SDK
How we generated the SDKs​
The available SDKs were developed using the OpenAPI Generator CLI, a robust tool designed to create client libraries directly from OpenAPI specifications.
Installation​
pip install openapi-generator-cli==7.10.0
SDK Setup Guide​
Python
JavaScript
Go

General CLI structure​
openapi-generator-cli generate \
-i rest_api_spec_h2ogpte.yaml \
-g python \
-o sdk \
--additional-properties=packageName=h2ogpte_rest_client,packageVersion=1.6.2,projectName=h2ogpte-rest-client
Prerequisites​
-
Create a folder for your Python SDK. Paste the following commands in your terminal:
mkdir python-sdk
cd python-sdk -
Download the OpenAPI specification file: Download api-spec.yaml and move it to the python-sdk folder.
-
Set up a Python environment with Python 3.8 or later:
python3 -m venv venv
source venv/bin/activate
pip install openapi-generator-cli==7.10.0
Generate SDK​
In the python-sdk directory, run the following command (CLI) to create the Python SDK using the OpenAPI Generator CLI:
openapi-generator-cli generate \
-i rest_api_spec_h2ogpte.yaml \
-g python \
-o sdk \
--additional-properties=packageName=h2ogpte_rest_client,packageVersion=1.6.2,projectName=h2ogpte-rest-client
The CLI creates a folder named sdk containing the Python SDK.
Install Dependencies​
-
Navigate to the SDK directory and install dependencies:
cd sdk
pip install -r requirements.txt -
Install the Python SDK:
pip install setuptools
python setup.py install
Test SDK with Collection Creation​
Create a test Collection to verify the Python SDK installation:
# This example with the Python SDK creates a new Collection with the following
# name and description (while testing whether the Python SDK was properly installed):
# Name = The name of my Collection
# Description = The description of my Collection
import h2ogpte_rest_client
import os
from h2ogpte_rest_client.rest import ApiException
from pprint import pprint
configuration = h2ogpte_rest_client.Configuration(
# This line specifies the URL where Enterprise h2oGPTe is hosted.
# The address should be the location where the API key was created.
host="https://h2ogpte.genai.h2o.ai/",
# This line specifies the API key for authentication.
access_token=os.environ["BEARER_TOKEN"]
)
with h2ogpte_rest_client.ApiClient(configuration) as api_client:
api_instance = h2ogpte_rest_client.CollectionsApi(api_client)
collection_create_request = h2ogpte_rest_client.CollectionCreateRequest(
name="The name of my Collection",
description="The description of my Collection"
)
try:
api_response = api_instance.create_collection(collection_create_request)
print("The response of CollectionsApi->create_collection:\n")
pprint(api_response)
except Exception as e:
print("Exception when calling CollectionsApi->create_collection: %s\n" % e)
Set up authentication:
Before you can run the Python script, you need to export a global API key within the sdk directory:
export BEARER_TOKEN="sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
Run the test:
Within the sdk directory, run the following command:
python3 create_a_collection.py
Expected output:
The response of CollectionsApi->create_collection:
Collection(id='091c6ab1-a031-4eb7-9e3e-7d0939911d00', name='The name of my Collection', description='The description of my Collection', embedding_model='BAAI/bge-large-en-v1.5', document_count=0, document_size=0, updated_at=datetime.datetime(2024, 12, 3, 21, 39, 49, 442087, tzinfo=TzInfo(UTC)), user_count=0, is_public=False, username='sergio.perez@h2o.ai', sessions_count=0)

General CLI structure​
openapi-generator-cli generate \
-i rest_api_spec_h2ogpte.yaml \
-g javascript \
-o sdk \
--additional-properties=packageName=h2ogpte-rest-client,packageVersion=1.6.2,projectName=h2ogpte-rest-client,npmName=h2ogpte-rest-client,npmVersion=h2ogpte-rest-client
Prerequisites​
-
Create a folder for your JavaScript SDK. Paste the following commands in your terminal:
mkdir javascript-sdk
cd javascript-sdk -
Download the OpenAPI specification file: Download api-spec.yaml and move it to the javascript-sdk folder.
-
Set up a Python environment (needed for OpenAPI Generator CLI):
python3 -m venv venv
source venv/bin/activate
pip install openapi-generator-cli==7.10.0
Generate SDK​
In the javascript-sdk directory, run the following command (CLI) to create the JavaScript SDK using the OpenAPI Generator CLI:
openapi-generator-cli generate \
-i rest_api_spec_h2ogpte.yaml \
-g javascript \
-o sdk \
--additional-properties=packageName=h2ogpte-rest-client,packageVersion=1.6.2,projectName=h2ogpte-rest-client,npmName=h2ogpte-rest-client,npmVersion=h2ogpte-rest-client
The CLI creates a folder named sdk containing the JavaScript SDK.
Install Dependencies​
-
Install the SDK dependencies:
cd sdk
npm install -
Link the library globally in npm:
npm link
-
Create a Node.js project to test the SDK:
cd ..
mkdir my-javascript-sdk-project
cd my-javascript-sdk-project
npm init -y -
Link the SDK to your project:
npm link /path/to/<THE_SDK_FOLDER>
-
Build the SDK module:
cd ../sdk
npm run build
Test SDK with Collection Creation​
Create a test Collection to verify the JavaScript SDK installation:
// This example with the JavaScript SDK creates a new Collection with the following
// name and description (while testing whether the SDK was properly installed):
// Name = The name of my Collection
// Description = The description of my Collection
import H2ogpteRestClient from 'h2ogpte-rest-client';
let defaultClient = H2ogpteRestClient.ApiClient.instance;
let bearerAuth = defaultClient.authentications['bearerAuth'];
// The access token should be a global API key.
bearerAuth.accessToken = "sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
let apiInstance = new H2ogpteRestClient.CollectionsApi();
let collectionCreateRequest = new H2ogpteRestClient.CollectionCreateRequest(
"The name of my Collection", // name parameter
"The description of my Collection" // description parameter
);
apiInstance.createCollection(collectionCreateRequest, (error, data, response) => {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
});
Run the test:
node create-a-collection.mjs

General CLI structure​
openapi-generator-cli generate \
-i rest_api_spec_h2ogpte.yaml \
-g go \
-o h2ogpte_rest_client \
--additional-properties=packageName=h2ogpte_rest_client,packageVersion=1.6.2,projectName=h2ogpte_rest_client,goModuleName=h2ogpte_rest_client,isGoSubmodule=true
Prerequisites​
-
Create a Go project. Paste the following commands in your terminal:
mkdir my-project
cd my-project
go mod init my-project -
Download the OpenAPI specification file: Download api-spec.yaml and move it to the my-project folder.
-
Set up a Python environment (needed for OpenAPI Generator CLI):
python3 -m venv venv
source venv/bin/activate
pip install openapi-generator-cli==7.10.0
Generate SDK​
In the go-sdk directory, run the following command (CLI) to create the Go SDK using the OpenAPI Generator CLI:
openapi-generator-cli generate \
-i rest_api_spec_h2ogpte.yaml \
-g go \
-o h2ogpte_rest_client \
--additional-properties=packageName=h2ogpte_rest_client,packageVersion=1.6.2,projectName=h2ogpte_rest_client,goModuleName=h2ogpte_rest_client,isGoSubmodule=true
Install Dependencies​
Create a work file to add the SDK module:
go work init
go work use ./h2ogpte_rest_client
Test SDK with Collection Creation​
Create a test Collection to verify the Go SDK installation:
package main
import (
"context"
"fmt"
"os"
openapiclient "github.com/GIT_USER_ID/GIT_REPO_ID/h2ogpte_rest_client"
)
func main() {
collectionCreateRequest := *openapiclient.NewCollectionCreateRequest("The name of my Collection", "The description of my Collection") // CollectionCreateRequest |
configuration := openapiclient.NewConfiguration()
configuration.AddDefaultHeader("Authorization","Bearer sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
apiClient := openapiclient.NewAPIClient(configuration)
resp, r, err := apiClient.CollectionsAPI.CreateCollection(context.Background()).CollectionCreateRequest(collectionCreateRequest).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `CollectionsAPI.CreateCollection``: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
// response from `CreateCollection`: Collection
fmt.Fprintf(os.Stdout, "Response from `CollectionsAPI.CreateCollection`: %v\n", resp)
}
Run the test:
go run create_a_collection.go
Expected output:
Response from `CollectionsAPI.CreateCollection`: &{e6926802-9529-419f-9ddd-cbb262137a8a The name of my Collection The description of my Collection BAAI/bge-large-en-v1.5 0 0 2024-12-11 23:43:19.972726 +0000 UTC 0 false sergio.perez@h2o.ai 0 <nil>}
CLI Parameters​
-i
: The path or URL to the OpenAPI spec (for example,openapi.yaml
orhttps://example.com/openapi.yaml
).-g
: The target programming language for the client (for example,python
,javascript
,go
).-o
: The output directory for the generated files (for example,./python-client
).--additional-properties
: Additional settings for client generation (for example,usePromises=true
for JavaScript).
For more information about generating SDKs in other languages, visit the OpenAPI Generator CLI documentation.
Authentication​
- The value exported for the
BEARER_TOKEN
(Python),accessToken
(JavaScript), orAuthorization
header (Go) should be a global API key. - To learn more about what is a global API key and how to create one, see APIs.
- All URIs are relative to https://h2ogpte.genai.h2o.ai/. The global API key must be created on this platform to ensure successful requests.
- Make sure to replace
sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
with your actual API key.
- Submit and view feedback for this page
- Send feedback about Enterprise h2oGPTe to cloud-feedback@h2o.ai