Athina Client SDK
Athina Client is a lightweight Python SDK designed to interact with Athina's datasets and API. It enables users to log LLM inferences, evaluations, and experiments for monitoring, analysis, and debugging AI applications. The current version is 0.2.11, with new releases occurring regularly, typically a few times a month, especially for minor fixes and feature additions.
Common errors
-
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url:
cause The provided Athina API key is either missing, invalid, or expired.fixVerify that the `ATHINA_API_KEY` environment variable is correctly set with a valid key, or ensure the `api_key` argument is passed correctly during `AthinaClient` initialization. -
AttributeError: 'module' object has no attribute 'log_inference'
cause Attempting to call `log_inference` (or `log_evaluation`) directly from the `athina` module, which was deprecated in favor of calling it on an `AthinaClient` instance.fixInitialize `athina_client = AthinaClient(...)` and then use `athina_client.log_inference(...)`. -
TypeError: 'NoneType' object is not callable
cause This often occurs if the `AthinaClient` object was not correctly instantiated (e.g., due to an error during `__init__`) or if a method was called on a `None` object, which can happen if `AthinaClient(...)` failed to return an instance.fixCheck for errors during `AthinaClient` initialization, especially related to the `api_key`. Ensure the client object is valid before calling its methods.
Warnings
- breaking The methods `log_inference` and `log_evaluation` were moved from directly under the `athina` module to be methods of the `AthinaClient` instance. If you were calling `athina.log_inference(...)`, you now need an instantiated client: `athina_client.log_inference(...)`.
- gotcha Failure to set the `ATHINA_API_KEY` environment variable or pass it directly to `AthinaClient(api_key=...)` will result in authentication errors (401 Unauthorized) when making API calls.
- breaking The `log_experiment` method in `AthinaClient` removed the `batch_size` parameter.
Install
-
pip install athina-client
Imports
- AthinaClient
from athina.client import AthinaClient
- AthinaInference
from athina.client import AthinaInference
from athina.interfaces.athina import AthinaInference
Quickstart
import os
from athina.client import AthinaClient
# Initialize the Athina client with your API key
athina_client = AthinaClient(api_key=os.environ.get("ATHINA_API_KEY", ""))
# Example 1: Log an inference
try:
response = athina_client.log_inference(
prompt="What is the capital of France?",
response="Paris",
external_reference_id="my-app-inference-123",
user_query="Capital question"
)
print(f"Inference logged successfully: {response.json()}")
except Exception as e:
print(f"Error logging inference: {e}")
# Example 2: Log a simple evaluation
try:
response = athina_client.log_evaluation(
external_reference_id="my-app-evaluation-456",
metric="correctness",
score=1, # 1 for correct, 0 for incorrect
details="The response was accurate.",
language_model_id="gpt-4"
)
print(f"Evaluation logged successfully: {response.json()}")
except Exception as e:
print(f"Error logging evaluation: {e}")