agent-infra-sdk 0.1.1

Gateway-backed Rust SDK for Agent Infra APIs
Documentation
//! Model Infra data-plane client.
//!
//! The Model service exposes OpenAI-compatible JSON at `/v1/*`. Keeping this
//! SDK boundary JSON-shaped avoids coupling runtime consumers to one provider
//! protocol crate while still centralising credentials, deadlines, retries,
//! response limits, and Gateway routing in [`HttpTransport`].

use reqwest::Client;
use serde_json::Value;

use crate::transport::{
    CallOptions, ClientOptions, HttpTransport, InfraClientError, ServiceEndpoint,
};

const CHAT_COMPLETIONS_PATH: &str = "/v1/model/chat/completions";
const RESPONSES_PATH: &str = "/v1/model/responses";
const MODELS_PATH: &str = "/v1/model/models";
const SERVICE_NAME: &str = "agent-model-infra";
const AUDIENCE: &str = "agent-model-infra";

/// Typed transport owner for Model Infra's JSON data plane.
#[derive(Clone, Debug)]
pub struct ModelClient {
    transport: HttpTransport,
}

impl ModelClient {
    pub(crate) fn new_with_endpoint(
        http: Client,
        endpoint: ServiceEndpoint,
        options: ClientOptions,
    ) -> Self {
        let endpoint = endpoint.with_default_credential_audience(AUDIENCE);
        Self {
            transport: HttpTransport::new_with_options(http, SERVICE_NAME, endpoint, options),
        }
    }

    /// Invoke the OpenAI-compatible chat-completions endpoint.
    pub async fn chat_completions(
        &self,
        request: &Value,
        options: CallOptions,
    ) -> Result<Value, InfraClientError> {
        self.transport
            .post_json_with_options(CHAT_COMPLETIONS_PATH, request, options)
            .await
    }

    /// Invoke the OpenAI-compatible Responses endpoint.
    pub async fn responses(
        &self,
        request: &Value,
        options: CallOptions,
    ) -> Result<Value, InfraClientError> {
        self.transport
            .post_json_with_options(RESPONSES_PATH, request, options)
            .await
    }

    pub async fn models(&self) -> Result<Value, InfraClientError> {
        self.transport.get_json(MODELS_PATH).await
    }
}