SDK configuration
SDK Configuration
This guide covers configuration for both Python and TypeScript SDKs, including basic setup, advanced options, and debugging capabilities.
Getting Started
Python SDK
The recommended approach to configuring the Python SDK is to use the opik configure command. This will prompt you to set up your API key and Opik instance URL (if applicable) to ensure proper routing and authentication. All details will be saved 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:
You can also configure the SDK by calling configure from the Command line:
The configure methods will prompt you for the necessary information and save it to a configuration file (~/.opik.config). When using the command line version, you can use the -y or --yes flag to automatically approve any confirmation prompts:
Connecting your AI coding assistant
At the end of setup, opik configure offers to register Opik’s MCP server with the AI clients it finds on your machine, so your assistant can read traces and log scores directly from the chat.
Pass --install-mcp to skip the prompt and register it:
opik configure also offers the Opik skill pack, which teaches your assistant
how to instrument code, run test suites, and use opik connect.
--install-skills installs it without the prompt:
These flags are what make the step work without a terminal, which is how a coding agent asked to “set Opik up” runs it:
Without a terminal the configuration defaults are assumed, so no -y is
needed; --install-mcp / --install-skills are the request to write into your
AI client’s configuration. A run that names
neither and has no terminal does nothing — so CI and Docker builds stay
untouched unless you ask.
--yes on its own deliberately registers neither the MCP server nor the skill
pack: both reach into another tool’s configuration, so they have to be asked for
explicitly. Use --no-install-mcp / --no-install-skills to skip the prompts
without being asked.
To set this up without re-running the whole configuration, use opik mcp configure — see Opik’s MCP server for the --ai-client flag, the skill pack, and per-client instructions.
TypeScript SDK
For the TypeScript SDK, configuration is done through environment variables, constructor options, or configuration files.
Installation:
Basic Configuration:
You can configure the Opik client using environment variables in a .env file:
Or pass configuration directly to the constructor:
Configuration Methods
Both SDKs support multiple configuration approaches with different precedence orders.
Configuration Precedence
Python SDK: Constructor options → Environment variables → Configuration file → Defaults
TypeScript SDK: Constructor options → Environment variables → Configuration file (~/.opik.config) → Defaults
Environment Variables
Both SDKs support environment variables for configuration. Here’s a comparison of available options:
Using .env Files
Both SDKs support .env files for managing environment variables. This is a good practice to avoid hardcoding secrets and to make your configuration more portable.
For Python projects, install python-dotenv:
For TypeScript projects, dotenv is automatically loaded by the SDK.
Create a .env file in your project’s root directory:
Python usage with .env file:
TypeScript usage with .env file:
The TypeScript SDK automatically loads .env files, so no additional setup is required:
Using Configuration Files
Both SDKs support configuration files for persistent settings.
Python SDK Configuration File
The Python SDK uses the TOML format. The configure method creates this file automatically, but you can also create it manually:
Opik Cloud
Self-hosting
TypeScript SDK Configuration File
The TypeScript SDK also supports the same ~/.opik.config file format as the Python SDK. The configuration file uses INI format internally but shares the same structure:
Opik Cloud
Self-hosting
By default, both SDKs look for the configuration file in your home directory (~/.opik.config). You can specify a
different location by setting the OPIK_CONFIG_PATH environment variable.
Debug Mode and Logging
Both SDKs provide debug capabilities for troubleshooting integration issues.
Python SDK Logging
The Python SDK provides two separate logging channels that can be configured independently:
- Console Logging: Controls log output to the console (stdout/stderr)
- File Logging: Controls log output to a file
Both channels support the following log levels: DEBUG, INFO (default), WARNING, ERROR, CRITICAL
Controlling Console Logging
To control the console log level, set the OPIK_CONSOLE_LOGGING_LEVEL environment variable before importing opik:
Available log levels for console:
DEBUG: Show all debug informationINFO: Show informational messages (default)WARNING: Show only warnings and errorsERROR: Show only errors and critical messagesCRITICAL: Show only critical errors
Using with .env file:
The Opik SDK manages its own logging configuration. Setting log levels through Python’s standard logging.getLogger("opik").setLevel() will not work. Always use the OPIK_CONSOLE_LOGGING_LEVEL environment variable to control console output.
Enabling File Logging for Debug
To enable debug mode with file logging, set these environment variables before importing opik:
Using with .env file:
Example combining both console and file logging:
Then in your Python script:
TypeScript SDK Debug Mode
The TypeScript SDK uses structured logging with configurable levels:
Available log levels: SILLY, TRACE, DEBUG, INFO (default), WARN, ERROR, FATAL
Enable debug logging:
Or in .env file:
Programmatic control:
Advanced Configuration
Python SDK Advanced Options
HTTP Client Configuration
The Opik Python SDK uses the httpx library to make HTTP requests. The default configuration applied to the HTTP client is suitable for most use cases, but you can customize it by registering a custom httpx client hook as in following example:
Make sure to add the hook before using the Opik SDK.
TypeScript SDK Advanced Options
Batching Configuration
The TypeScript SDK uses batching for optimal performance. You can configure batching behavior:
Global Flush Control
Usage analytics
The Python SDK reports usage analytics that tell us which SDK features are being used, so we know what to invest in. Each API you call is reported once per run, by name only, alongside the same environment details the SDK already reports with error reports: the SDK and Python versions, the OS, whether you are in Jupyter, Colab or CI, the kind of installation (cloud, self-hosted or local), and the versions of the LLM libraries installed next to Opik.
Usage is attributed to your workspace name — the same identifier used for error reporting, so that an error and the usage around it describe the same user. Installations left on the default workspace are attributed to a one-way hash of the hostname and username instead.
Never sent: the contents of your traces, spans, prompts, datasets or evaluation results, your API key, or your project names. Reporting always happens on a background thread and never affects your application.
Events are sent to Comet’s usage-reporting endpoint, the same pipeline the Opik UI and backend already report through.
To turn it off:
Configuration Reference
Python SDK Configuration Values
TypeScript SDK Configuration Values
Troubleshooting
Python SDK Troubleshooting
SSL Certificate Error
If you encounter the following error:
You can resolve it by either:
- Disable the TLS certificate check by setting the
OPIK_CHECK_TLS_CERTIFICATEenvironment variable tofalse - Add the Opik server’s certificate to your trusted certificates by setting the
REQUESTS_CA_BUNDLEenvironment variable
Health Check Command
If you are experiencing problems with the Python SDK, such as receiving 400 or 500 errors from the backend, or being unable to connect at all, run the health check command:
This command will analyze your configuration and backend connectivity, providing useful insights into potential issues.

Reviewing the health check output can help pinpoint the source of the problem and suggest possible resolutions.
TypeScript SDK Troubleshooting
Configuration Validation Errors
The TypeScript SDK validates configuration at startup. Common errors:
- “OPIK_URL_OVERRIDE is not set”: Set the
OPIK_URL_OVERRIDEenvironment variable - “OPIK_API_KEY is not set”: Required for Opik Cloud deployments
- “OPIK_WORKSPACE is not set”: Optional, but can be set for Opik Cloud deployments
Debug Logging
Enable debug logging to troubleshoot issues:
If you are using the Opik Optimizer SDK, you can also enable optimizer-side debug logs:
Or programmatically:
Batch Queue Issues
If data isn’t appearing in Opik:
- Check if data is batched: Call
await client.flush()to force sending - Verify configuration: Ensure correct API URL and credentials
- Check network connectivity: Verify firewall and proxy settings
General Troubleshooting
Environment Variables Not Loading
- Python: Ensure
load_dotenv()is called before importingopik - TypeScript: The SDK automatically loads
.envfiles - Verify file location:
.envfile should be in project root - Check file format: No spaces around
=in.envfiles
Configuration File Issues
- File location: Default is
~/.opik.config - Custom location: Use
OPIK_CONFIG_PATHenvironment variable - File format: Python uses TOML, TypeScript uses INI format
- Permissions: Ensure file is readable by your application