Python SDK Configuration
The recommended approach to configuring the Python SDK is to use the opik configure
command. This will prompt you for the necessary information and save it to a configuration file.
- Opik Cloud
- Self-hosting
If you are using the Cloud version of the platform, you can configure the SDK by running:
import opik
opik.configure(use_local=False)
You can also configure the SDK by calling configure
from the Command line:
opik configure
If you are self-hosting the platform, you can configure the SDK by running:
import opik
opik.configure(use_local=True)
or from the Command line:
opik configure --use_local
The configure
methods will prompt you for the necessary information and save it to a configuration file (~/.opik.config
).
Advanced usage
In addition to the configure
method, you can also configure the Python SDK in a couple of different ways:
- Using a configuration file
- Using environment variables
Using a configuration file
The configure
method is a helper method to help you create the Opik SDK configuration file but you can also manually create the configuration file.
The Opik configuration file follows the TOML format, here is an example configuration file:
- Opik Cloud
- Self-hosting
[opik]
url_override = https://www.comet.com/opik/api
workspace = <Workspace name>
api_key = <API Key>
[opik]
url_override = http://localhost:5173/api
workspace = default
You can find a full list of the the configuration options in the Configuration values section below.
By default, the SDK will look for the configuration file in your home directory (~/.opik.config
). If you would like to specify a different location, you can do so by setting the OPIK_CONFIG_PATH
environment variable.
Using environment variables
If you do not wish to use a configuration file, you can set environment variables to configure the SDK. The most common configuration values are:
OPIK_URL_OVERRIDE
: The URL of the Opik server to use - Defaults tohttps://www.comet.com/opik/api
OPIK_API_KEY
: The API key to use - Only required if you are using the Opik Cloud version of the platformOPIK_WORKSPACE
: The workspace to use - Only required if you are using the Opik Cloud version of the platform
You can find a full list of the the configuration options in the Configuration values section below.
Configuration values
Here is a list of the configuration values that you can set:
Configuration Name | Environment variable | Description |
---|---|---|
url_override | OPIK_URL_OVERRIDE | The URL of the Opik server to use - Defaults to https://www.comet.com/opik/api |
api_key | OPIK_API_KEY | The API key to use - Only required if you are using the Opik Cloud version of the platform |
workspace | OPIK_WORKSPACE | The workspace to use - Only required if you are using the Opik Cloud version of the platform |
project_name | OPIK_PROJECT_NAME | The project name to use |
default_flush_timeout | OPIK_DEFAULT_FLUSH_TIMEOUT | The default flush timeout to use - Defaults to no timeout |
opik_check_tls_certificate | OPIK_CHECK_TLS_CERTIFICATE | Flag to check the TLS certificate of the Opik server - Defaults to true |
Common error messages
SSL certificate error
If you encounter the following error:
[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self-signed certificate in certificate chain (_ssl.c:1006)
You can resolve it by either:
- Disable the TLS certificate check by setting the
OPIK_CHECK_TLS_CERTIFICATE
environment variable tofalse
- Add the Opik server's certificate to your trusted certificates by setting the
REQUESTS_CA_BUNDLE
environment variable