Skip to main content

data_for_seo/entity/ai_optimization/
llm_responses.rs

1//! Models for the LLM Responses sub-API (ChatGPT, Claude, Gemini, Perplexity).
2//!
3//! See <https://docs.dataforseo.com/v3/ai_optimization/chat_gpt/llm_responses/overview/>.
4
5use serde::{Deserialize, Serialize};
6use serde_json::Value;
7
8/// A model advertised by a provider's `models` endpoint.
9///
10/// See <https://docs.dataforseo.com/v3/ai_optimization/chat_gpt/llm_responses/models/>.
11#[derive(Debug, Default, Serialize, Deserialize, Clone)]
12pub struct AiOptimizationLlmResponseModel {
13    /// Identifier of the model (e.g. `"gpt-4.1-mini"`).
14    pub model_name: Option<String>,
15    /// Whether the model is a reasoning model.
16    pub reasoning: Option<bool>,
17    /// Whether the model supports web search.
18    pub web_search_supported: Option<bool>,
19    /// Whether the model supports the Standard (`task_post`) method.
20    pub task_post_supported: Option<bool>,
21}
22
23/// A source citation attached to a response section.
24#[derive(Debug, Default, Serialize, Deserialize, Clone)]
25pub struct AiOptimizationLlmResponseAnnotation {
26    /// Title of the cited source.
27    pub title: Option<String>,
28    /// URL of the cited source.
29    pub url: Option<String>,
30}
31
32/// A content section inside a response item.
33#[derive(Debug, Default, Serialize, Deserialize, Clone)]
34pub struct AiOptimizationLlmResponseSection {
35    /// Section type (`"text"`, `"summary_text"`, ...).
36    #[serde(rename = "type")]
37    pub section_type: Option<String>,
38    /// Text content of the section.
39    pub text: Option<String>,
40    /// Source citations referenced by the section.
41    pub annotations: Option<Vec<AiOptimizationLlmResponseAnnotation>>,
42}
43
44/// An item of an LLM response (either a `reasoning` or a `message` block).
45#[derive(Debug, Default, Serialize, Deserialize, Clone)]
46pub struct AiOptimizationLlmResponseItem {
47    /// Item type (`"reasoning"` or `"message"`).
48    #[serde(rename = "type")]
49    pub item_type: Option<String>,
50    /// Content sections of the item.
51    pub sections: Option<Vec<AiOptimizationLlmResponseSection>>,
52}
53
54/// Result of the LLM Responses `live`, `task_post` and `task_get` endpoints.
55///
56/// See <https://docs.dataforseo.com/v3/ai_optimization/chat_gpt/llm_responses/live/>.
57#[derive(Debug, Default, Serialize, Deserialize, Clone)]
58pub struct AiOptimizationLlmResponse {
59    /// Actual model used to generate the response.
60    pub model_name: Option<String>,
61    /// Number of input (prompt) tokens.
62    pub input_tokens: Option<i64>,
63    /// Number of output (completion) tokens.
64    pub output_tokens: Option<i64>,
65    /// Number of reasoning tokens (reasoning models only).
66    pub reasoning_tokens: Option<i64>,
67    /// Whether web search was used to produce the response.
68    pub web_search: Option<bool>,
69    /// Third-party AI provider cost in USD.
70    pub money_spent: Option<f64>,
71    /// UTC timestamp the response was generated.
72    pub datetime: Option<String>,
73    /// Response content items (reasoning and message blocks).
74    pub items: Option<Vec<AiOptimizationLlmResponseItem>>,
75    /// Related fan-out search queries (raw JSON).
76    pub fan_out_queries: Option<Value>,
77}