{"id":6704,"library":"literalai","title":"Literal AI SDK","description":"The Literal AI Python SDK provides observability for large language model (LLM) applications. It enables developers to trace, monitor, and debug their LLM interactions and application flows directly from their Python code. As of version 0.1.300, it's an actively developed library with frequent releases in its 0.1.x series, indicating ongoing feature development and potential API refinements.","status":"active","version":"0.1.300","language":"en","source_language":"en","source_url":"https://github.com/LiteralAI/literal-python","tags":["AI","LLM","observability","tracing","developer-tools"],"install":[{"cmd":"pip install literalai","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"symbol":"LiteralClient","correct":"from literalai import LiteralClient"},{"note":"Used for accessing the current trace context, e.g., to manually add steps or properties.","symbol":"get_literal_context","correct":"from literalai import get_literal_context"}],"quickstart":{"code":"import os\nfrom literalai import LiteralClient\n\n# Initialize the client with your API key\n# Ensure LITERAL_API_KEY environment variable is set or pass it directly\nclient = LiteralClient(api_key=os.environ.get(\"LITERAL_API_KEY\", \"\"))\n\n@client.trace(name=\"my_simple_llm_call_trace\")\ndef my_simple_llm_call(prompt: str):\n    \"\"\"Simulates an LLM call and returns a response.\"\"\"\n    print(f\"Processing prompt: {prompt}\")\n    response = f\"Simulated response to: {prompt}\"\n    # In a real scenario, this would involve calling an actual LLM\n    # e.g., OpenAI, Anthropic, etc., and potentially logging its output\n    return {\"output\": response, \"model\": \"simulated-model-v1\"}\n\n# Run the traced function\nif os.environ.get(\"LITERAL_API_KEY\"):\n    result = my_simple_llm_call(\"Tell me a short story about a brave knight.\")\n    print(f\"Trace result: {result}\")\nelse:\n    print(\"LITERAL_API_KEY not set. Skipping trace execution. Please set it to run the example.\")","lang":"python","description":"This quickstart initializes the Literal AI client and demonstrates how to trace a simple function representing an LLM call using the `@client.trace` decorator. It checks for the `LITERAL_API_KEY` environment variable to ensure the example runs correctly."},"warnings":[{"fix":"Ensure `LITERAL_API_KEY` is set in your environment. If you're using an older client, update to the latest version and verify your authentication method.","message":"The `LITERAL_API_KEY` environment variable is required for authentication with the Literal AI platform. While older versions (specifically around `0.1.139`) experimented with `LITERAL_CLIENT_ID` and `LITERAL_CLIENT_SECRET`, the current recommended and supported method for the `0.1.x` series uses a single `LITERAL_API_KEY`.","severity":"gotcha","affected_versions":"All versions. Particularly confusing for users migrating from specific previous experimental versions around `0.1.139`."},{"fix":"Regularly check release notes for breaking changes when updating the library. Pin your dependency version if stability is critical, and plan for periodic updates and code adjustments.","message":"As the library is in its `0.1.x` release series, API contracts can change between minor versions (e.g., `0.1.X` to `0.1.Y`) without strict adherence to semantic versioning. Frequent updates may introduce breaking changes to method signatures, class names, or expected parameters.","severity":"breaking","affected_versions":"All `0.1.x` versions."},{"fix":"Identify whether you are operating in synchronous or asynchronous contexts and use the appropriate client methods and `await` keyword. For example, use `@client.atrace` decorator for async functions.","message":"When working with asynchronous code (e.g., `async def` functions), ensure you use `await` with Literal AI's async methods (e.g., `await client.atrack()`, `await client.atrace()`). Incorrectly mixing synchronous and asynchronous calls can lead to `RuntimeWarning`s, unhandled exceptions, or unexpected behavior in tracing.","severity":"gotcha","affected_versions":"All versions with async support."}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}