"""Real provider calls. Skipped unless EST_LIVE_LLM=1 and the keys are set. EST_LIVE_LLM=1 EST_LLM__ANTHROPIC__API_KEY=... EST_LLM__OPENAI__API_KEY=... \ pytest tests/integration/test_llm_live.py -m live -s Set the OpenAI model in EST_LIVE_OPENAI_MODEL and the Anthropic one in EST_LIVE_ANTHROPIC_MODEL. """ import os import pytest from pydantic import BaseModel from estimator.infra.llm import AnthropicClient, OpenAIChatClient pytestmark = [ pytest.mark.live, pytest.mark.skipif(os.getenv("EST_LIVE_LLM") != "1", reason="set EST_LIVE_LLM=1 to run"), ] class Capital(BaseModel): country: str capital: str PROMPT = "Name the capital of Finland. Answer with country and capital." async def test_anthropic_live(): key = os.environ["EST_LLM__ANTHROPIC__API_KEY"] model = os.getenv("EST_LIVE_ANTHROPIC_MODEL", "claude-sonnet-5-5") c = AnthropicClient(base_url="https://api.anthropic.com", api_key=key) try: res = await c.structured(system="Be brief.", user=PROMPT, schema=Capital, model=model, max_tokens=300) finally: await c.aclose() assert res.parsed.capital.lower().startswith("helsinki") assert res.usage.input_tokens > 0 async def test_openai_live(): key = os.environ["EST_LLM__OPENAI__API_KEY"] model = os.environ["EST_LIVE_OPENAI_MODEL"] c = OpenAIChatClient(base_url="https://api.openai.com/v1", api_key=key) try: res = await c.structured(system="Be brief.", user=PROMPT, schema=Capital, model=model, max_tokens=500) finally: await c.aclose() assert res.parsed.capital.lower().startswith("helsinki") assert res.usage.input_tokens > 0