Skip to main content
Version: 0.0.42

Session Completions

This use case covers sending an analytical question to a Lakehousecat model and receiving the answer — including a reference to the generated chart. It mirrors the core interaction in the Lakehousecat session UI.

Prerequisites​

Before sending a session completion request, the following must already exist in Lakehousecat:

  1. A Provider Model configured with valid API credentials (e.g., Anthropic, OpenAI)
  2. A Datasource connected and with semantic extraction completed
  3. A Custom Model bound to the datasource

If these are not yet set up, see Manage Datasources or complete the setup via the Lakehousecat UI.

How it works​

Internally, a session completion triggers the following sequence:

  1. The LLM service receives the question and the model ID
  2. It loads the semantic layer (table/column descriptions) for the bound datasource
  3. It generates SQL, executes it via the Analytics service
  4. It returns the answer text plus a chart_id reference

You do not need to call these services individually — a single completion request triggers the full pipeline.

Send a Session Completion​

curl -X POST "$LHC_LLM/api/v1/llm/session/completions" \
-H "Authorization: Bearer $LHC_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"model": "<model-id>",
"messages": [
{"role": "user", "content": "What is total revenue by region this year?"}
]
}'
response = requests.post(
f"{LLM}/api/v1/llm/session/completions",
headers=HEADERS,
json={
"model": "<model-id>",
"messages": [
{"role": "user", "content": "What is total revenue by region this year?"}
],
},
).json()

answer = response["choices"][0]["message"]["content"]
chart_id = response.get("chart_id") # present if a chart was generated

print(answer)
print(f"Chart: {chart_id}")

Multi-Turn Conversation​

Include the full conversation history in messages to maintain context across turns:

messages = [
{"role": "user", "content": "Show me monthly revenue for this year."},
{"role": "assistant", "content": "<previous answer>"},
{"role": "user", "content": "Now break it down by product category."},
]

response = requests.post(
f"{LLM}/api/v1/llm/session/completions",
headers=HEADERS,
json={"model": "<model-id>", "messages": messages},
).json()

Get the Model ID​

List available models to find the correct model ID:

curl -s "$LHC_CORE/api/v1/lhc/models" \
-H "Authorization: Bearer $LHC_TOKEN"
models = requests.get(f"{CORE}/api/v1/lhc/models", headers=HEADERS).json()
for m in models:
print(m["id"], m["name"])

Next Steps​

  • Retrieve Charts — fetch and embed charts referenced in completion responses