Skip to content

AggregatedMetricsItemInfo.key is a string but location.key is an integer (llm_mentions target_metrics) #19

Open

Description

@urwalms

AggregatedMetricsItemInfo.key is typed as a string, but the API returns an integer in aggregated_metrics.location, so parsing the response of ai_optimization/llm_mentions/target_metrics/live raises a ValidationError.

The docs for this endpoint (https://docs.dataforseo.com/v3/ai_optimization/llm_mentions/target_metrics/live/) give key as an integer in location (a location code) and as a string in language and sources_domain. The model declares it as a string for all of them.

Version: dataforseo-client 2.1.9 and 2.1.10 (Python 3.14, pydantic 2.14)

Reproduction (no credentials needed; the body has the documented shape):

from dataforseo_client.models.ai_optimization_llm_mentions_target_metrics_live_response_info import (
    AiOptimizationLlmMentionsTargetMetricsLiveResponseInfo,
)

body = {
    "tasks": [
        {
            "result": [
                {
                    "aggregated_metrics": {
                        "location": [{"key": 2840, "mentions": 1, "ai_search_volume": 1}]
                    }
                }
            ]
        }
    ]
}
AiOptimizationLlmMentionsTargetMetricsLiveResponseInfo.from_dict(body)

Result

pydantic_core._pydantic_core.ValidationError: 1 validation error for AggregatedMetricsItemInfo
key
  Input should be a valid string [type=string_type, input_value=2840, input_type=int]

Effect: every real call to llm_mentions_target_metrics_live fails in the client even though the request succeeds and is billed (about $0.10 per call). The same response is returned normally by the raw-response method (..._without_preload_content), where the integer key is present. Callers that add up the cost only after a successful parse also miss the charge.

Suggestion: type key as Union[StrictStr, StrictInt], or give the location entries their own item model. I have not checked the other llm_mentions endpoints that share this item model (for example the top_mentioned_* ones).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions