pub struct OpenRouterClient { /* private fields */ }Expand description
OpenRouter API client for issue triage.
Holds HTTP client, API key, and model configuration for reuse across multiple requests. Enables connection pooling and cleaner API.
Implementations§
Source§impl OpenRouterClient
impl OpenRouterClient
Sourcepub fn new(config: &AiConfig) -> Result<Self>
pub fn new(config: &AiConfig) -> Result<Self>
Creates a new OpenRouter client from configuration.
Validates the model against cost control settings and fetches the API key from the environment.
§Arguments
config- AI configuration with model, timeout, and cost control settings
§Errors
Returns an error if:
- Model is not in free tier and
allow_paid_modelsis false OPENROUTER_API_KEYenvironment variable is not set- HTTP client creation fails
Sourcepub fn with_api_key(api_key: SecretString, config: &AiConfig) -> Result<Self>
pub fn with_api_key(api_key: SecretString, config: &AiConfig) -> Result<Self>
Creates a new OpenRouter client with a provided API key.
This constructor allows callers to provide an API key directly, enabling multi-platform credential resolution (e.g., from iOS keychain via FFI).
§Arguments
api_key-OpenRouterAPI key as aSecretStringconfig- AI configuration with model, timeout, and cost control settings
§Errors
Returns an error if:
- Model is not in free tier and
allow_paid_modelsis false - HTTP client creation fails
Sourcepub async fn analyze_issue(&self, issue: &IssueDetails) -> Result<AiResponse>
pub async fn analyze_issue(&self, issue: &IssueDetails) -> Result<AiResponse>
Analyzes a GitHub issue using the OpenRouter API.
Returns a structured triage response with summary, labels, questions, duplicates, and usage stats.
§Arguments
issue- Issue details to analyze
§Errors
Returns an error if:
- API request fails (network, timeout, rate limit)
- Response cannot be parsed as valid JSON
Sourcepub async fn create_issue(
&self,
title: &str,
body: &str,
repo: &str,
) -> Result<CreateIssueResponse>
pub async fn create_issue( &self, title: &str, body: &str, repo: &str, ) -> Result<CreateIssueResponse>
Creates a formatted GitHub issue using the OpenRouter API.
Takes raw issue title and body, formats them using AI (conventional commit style, structured body), and returns the formatted content with suggested labels.
§Arguments
title- Raw issue title from userbody- Raw issue body/description from userrepo- Repository name for context (owner/repo format)
§Errors
Returns an error if:
- API request fails (network, timeout, rate limit)
- Response cannot be parsed as valid JSON
Auto Trait Implementations§
impl Freeze for OpenRouterClient
impl !RefUnwindSafe for OpenRouterClient
impl Send for OpenRouterClient
impl Sync for OpenRouterClient
impl Unpin for OpenRouterClient
impl !UnwindSafe for OpenRouterClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more