Skip to main content

Initialization

To interact with the AI Engine Manager, you need to authenticate first. There are several options available:

Using the H2O Notebook Labs

If you are using the H2O Notebook Labs, your environment is already configured.

import h2o_engine_manager

clients = h2o_engine_manager.login()

Using the H2O CLI

On your local machine, the recommended way is to download and configure the H2O CLI. Visit the CLI & API Access section of H2O AI Cloud to get started. For more information, see Using the H2O CLI in the AI App Store documentation.

Verify your installation by running:

h2o platform token-info

With the H2O AI Cloud CLI configured, you can log in without providing any arguments.

import h2o_engine_manager

clients = h2o_engine_manager.login()

If your H2O AI Cloud CLI configuration file is in a non-standard location, you can pass the path using config_file argument.

import h2o_engine_manager

clients = h2o_engine_manager.login(config_path="/path/to/h2o-cli-config.toml")

Using the Platform Token

Log in to the H2O AI Cloud and visit the CLI & API Access section. This page will allow you to generate a platform token and provide a code example for you.

In a Wave app

Production

For Wave version 0.25.2 and later when deploying to H2O AI Cloud, use:

from h2o_wave import app, Q, main
import h2o_engine_manager

@app('/')
async def serve(q: Q):
clients = await q.run(h2o_engine_manager.login,
token_provider=q.auth.ensure_fresh_token_sync,
)

For older versions, you must provide the token provider. See h2o_authn package for more information.

import os
from h2o_wave import app, Q
import h2o_engine_manager
import h2o_authn

@app('/')
async def serve(q: Q):
provider = await q.run(h2o_authn.TokenProvider,
refresh_token=q.auth.refresh_token,
issuer_url=os.getenv("H2O_WAVE_OIDC_PROVIDER_URL"),
client_id=os.getenv("H2O_WAVE_OIDC_CLIENT_ID"),
client_secret=os.getenv("H2O_WAVE_OIDC_CLIENT_SECRET"),
)

clients = await q.run(h2o_engine_manager.login, token_provider=provider)
danger

Wrapping h2o_engine_manager calls within q.run is necessary for multiuser apps to work properly. Otherwise, they may block each other, resulting in poor app performance.

Development

For a local development of Wave apps, follow the Using the H2O CLI instructions above.

Custom

You can log in manually using the login_custom function. This is useful if you want to authenticate outside the H2O AI Cloud environment.

import h2o_engine_manager

clients = h2o_engine_manager.login_custom(
endpoint="https://enginemanager.cloud-dev.h2o.ai",
refresh_token="my-secret-refresh-token",
client_id="oidc-app-client-id",
client_secret="oidc-app-secret",
issuer_url="https://auth.cloud-dev.h2o.ai/auth/realms/hac-dev"
)

Feedback