Repository navigation
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
Summary
Two related issues observed querying openai_admin.usage.completions.
1. Function expressions in the WHERE clause are not evaluated for required parameters
When a required parameter is supplied via a function expression rather than a literal, the value is not resolved and the parameter is dropped from the request, producing a 400 from the provider.
SELECT
json_extract(r.value, '$.project_id') AS project_id,
json_extract(r.value, '$.model') AS model,
date(u.start_time, 'unixepoch') AS usage_date,
json_extract(r.value, '$.input_tokens') AS input_tokens,
json_extract(r.value, '$.output_tokens') AS output_tokens
FROM openai_admin.usage.completions u, json_each(u.results) r
WHERE u.start_time = strftime('%s', date('now', '-30 days'))
AND u.bucket_width = '1d'
AND u.group_by = 'project_id'
ORDER BY usage_date, project_id;Result:
http response status code: 400, response body: {
"error": {
"message": "Missing required parameter: 'start_time'.",
"type": "invalid_request_error",
"param": "start_time",
"code": "missing_required_parameter"
}
}
The expression itself evaluates fine standalone:
select strftime('%s', date('now', '-30 days'));
-- 1781481600The same query with the literal substituted does dispatch the request:
WHERE u.start_time = 1781481600Expected: scalar function expressions on the right hand side of a required parameter predicate are evaluated before request construction, and the resolved value is bound to the parameter.
2. Projected columns return null / zero when the request does succeed
With the literal form, the request succeeds but the projection is largely empty:
|-------------------------------|-------|------------|--------------|---------------|
| project_id | model | usage_date | input_tokens | output_tokens |
|-------------------------------|-------|------------|--------------|---------------|
| proj_RBWsjunhtdHqTO3MgxytkuB5 | null | 0 | null | null |
|-------------------------------|-------|------------|--------------|---------------|
Observations:
project_idresolves viajson_extract(r.value, '$.project_id'), sojson_each(u.results)is expanding correctly.input_tokensandoutput_tokensare null despite being siblings ofproject_idin the same result object.usage_dateis 0, indicatingu.start_timeis not projectable in the response row even though it was supplied as a parameter. Parameter values should be echoed into the row so they can be projected and joined against.modelmay legitimately be null givengroup_by = 'project_id', but should be confirmed.
Environment
- Provider:
openai_admin - Resource:
openai_admin.usage.completions - stackql version:
- Provider version:
Suspected areas
- Parameter binding path: literal-only extraction from the WHERE clause, function expressions ignored rather than evaluated or rejected.
- Response projection: parameter columns not merged into the emitted row; possible schema mismatch on the nested
results[].result[]shape for the usage endpoints.
Acceptance criteria
WHERE start_time = strftime('%s', date('now', '-30 days'))dispatches a request with the resolved epoch value.- If an expression cannot be evaluated at plan time, stackql returns a clear error rather than silently dropping the parameter.
- Projecting
u.start_timereturns the supplied parameter value. input_tokensandoutput_tokensreturn values from the response payload.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request
Activity
feat: constant-fold WHERE function expressions for provider parameters (
feat: mcp credential (re)sourcing via server.env_file + reload_creden…