Skip to main content

uarp_sdk/generated/api/
open_ai_compat.rs

1// Code generated by @uarp/codegen from spec/openapi.json. DO NOT EDIT.
2//!
3//! OpenAI-compatible ChatCompletion endpoint
4
5#![allow(unused_imports, clippy::too_many_arguments)]
6
7use reqwest::Method;
8use serde::{Deserialize, Serialize};
9
10use crate::client::{Client, Request, NO_BODY, NO_QUERY};
11use crate::error::Result;
12use crate::generated::models;
13use crate::multipart::{field_text, FilePart};
14use crate::util::encode_path;
15
16/// OpenAI-compatible ChatCompletion endpoint
17#[derive(Debug, Clone)]
18pub struct OpenAiCompatApi {
19    pub(crate) client: Client,
20}
21
22impl Client {
23    /// OpenAI-compatible ChatCompletion endpoint
24    pub fn open_ai_compat(&self) -> OpenAiCompatApi {
25        OpenAiCompatApi { client: self.clone() }
26    }
27}
28
29impl OpenAiCompatApi {
30    /// OpenAI-compatible chat completion
31    ///
32    /// Maps OpenAI ChatCompletion requests to UARP agent runs. The 'model' field maps to
33    /// 'agent/\<agent_id\>' or a plain agent_id.
34    ///
35    /// `POST /v1/chat/completions`
36    ///
37    /// Required scopes: `runs:create`.
38    pub async fn chat_completion(&self, body: &models::ChatCompletionRequest) -> Result<serde_json::Value> {
39        self.client
40            .request_json(Request {
41                method: Method::POST,
42                path: "/v1/chat/completions".to_string(),
43                query: NO_QUERY,
44                body: Some(body),
45                headers: Vec::new(),
46                idempotent: false,
47            })
48            .await
49    }
50
51    /// Create response (OpenAI Responses API)
52    ///
53    /// OpenAI-compatible Responses API. `model` and `input` required; `previous_response_id` chains
54    /// to a prior response; `instructions` overrides the agent's system prompt for this call.
55    ///
56    /// `POST /v1/responses`
57    ///
58    /// Required scopes: `runs:create`.
59    pub async fn create_response(&self, body: &models::CreateResponseRequest) -> Result<models::CreateResponseResponse> {
60        self.client
61            .request_json(Request {
62                method: Method::POST,
63                path: "/v1/responses".to_string(),
64                query: NO_QUERY,
65                body: Some(body),
66                headers: Vec::new(),
67                idempotent: false,
68            })
69            .await
70    }
71
72    /// OpenAI-compatible embeddings
73    ///
74    /// Generate embedding vectors for input text. Per Standats-Protocols ยง6.1. Uses
75    /// platform-configured model (text-embedding-3-small).
76    ///
77    /// `POST /v1/embeddings`
78    ///
79    /// Required scopes: `runs:create`.
80    pub async fn embeddings(&self, body: &models::EmbeddingsRequest) -> Result<models::EmbeddingsResponse> {
81        self.client
82            .request_json(Request {
83                method: Method::POST,
84                path: "/v1/embeddings".to_string(),
85                query: NO_QUERY,
86                body: Some(body),
87                headers: Vec::new(),
88                idempotent: false,
89            })
90            .await
91    }
92
93    /// Get response by ID (OpenAI Responses API)
94    ///
95    /// `GET /v1/responses/{responseId}`
96    pub async fn get_response(&self, response_id: &str) -> Result<serde_json::Value> {
97        self.client
98            .request_json(Request {
99                method: Method::GET,
100                path: format!("/v1/responses/{}", encode_path(response_id)),
101                query: NO_QUERY,
102                body: NO_BODY,
103                headers: Vec::new(),
104                idempotent: false,
105            })
106            .await
107    }
108
109    /// List available models (OpenAI-compatible)
110    ///
111    /// Returns agents as models in OpenAI model list format.
112    ///
113    /// `GET /v1/models`
114    pub async fn list_models(&self) -> Result<models::ListModelsResponse> {
115        self.client
116            .request_json(Request {
117                method: Method::GET,
118                path: "/v1/models".to_string(),
119                query: NO_QUERY,
120                body: NO_BODY,
121                headers: Vec::new(),
122                idempotent: false,
123            })
124            .await
125    }
126}