Skip to main content

InternalClient

Struct InternalClient 

Source
pub struct InternalClient;
Expand description

Stateless internal client for executing single-query sessions.

Unlike ClaudeSdkClient, this client does not maintain state between queries. Each call to process_query() creates a fresh connection, executes the query, and tears down the connection.

Implementations§

Source§

impl InternalClient

Source

pub fn new() -> Self

Creates a new InternalClient.

§Example
use claude_code::internal_client::InternalClient;

let _client = InternalClient::new();
Source

pub async fn process_query( &self, prompt: InputPrompt, options: ClaudeAgentOptions, transport: Option<Box<dyn Transport>>, ) -> Result<Vec<Message>>

Executes a complete query lifecycle: connect, send, receive all messages, and close.

§Example
use claude_code::internal_client::InternalClient;
use claude_code::{InputPrompt, ClaudeAgentOptions};

let client = InternalClient::new();
let _messages = client
    .process_query(
        InputPrompt::Text("hello".to_string()),
        ClaudeAgentOptions::default(),
        None,
    )
    .await?;
Source

pub async fn process_query_from_stream<S>( &self, prompt: S, options: ClaudeAgentOptions, transport: Option<Box<dyn Transport>>, ) -> Result<Vec<Message>>
where S: Stream<Item = Value> + Unpin,

Executes a one-shot query where input messages are provided as a stream.

§Example
use claude_code::internal_client::InternalClient;
use claude_code::ClaudeAgentOptions;
use futures::stream;
use serde_json::json;

let client = InternalClient::new();
let _messages = client
    .process_query_from_stream(
        stream::iter(vec![json!({"type":"user","message":{"role":"user","content":"hello"}})]),
        ClaudeAgentOptions::default(),
        None,
    )
    .await?;
Source

pub async fn process_query_as_stream( &self, prompt: InputPrompt, options: ClaudeAgentOptions, transport: Option<Box<dyn Transport>>, ) -> Result<BoxStream<'static, Result<Message>>>

Executes a one-shot query and returns a streaming response interface.

The returned stream is Send and can be consumed from any tokio task.

§Example
use claude_code::internal_client::InternalClient;
use claude_code::{InputPrompt, ClaudeAgentOptions};
use futures::StreamExt;

let client = InternalClient::new();
let mut stream = client
    .process_query_as_stream(
        InputPrompt::Text("hello".to_string()),
        ClaudeAgentOptions::default(),
        None,
    )
    .await?;

let _ = stream.next().await;
Source

pub async fn process_query_from_stream_as_stream<S>( &self, prompt: S, options: ClaudeAgentOptions, transport: Option<Box<dyn Transport>>, ) -> Result<BoxStream<'static, Result<Message>>>
where S: Stream<Item = Value> + Unpin,

Executes a one-shot streamed-input query and returns a streaming response interface.

§Example
use claude_code::internal_client::InternalClient;
use claude_code::ClaudeAgentOptions;
use futures::{stream, StreamExt};
use serde_json::json;

let client = InternalClient::new();
let mut stream = client
    .process_query_from_stream_as_stream(
        stream::iter(vec![json!({"type":"user","message":{"role":"user","content":"hello"}})]),
        ClaudeAgentOptions::default(),
        None,
    )
    .await?;

let _ = stream.next().await;

Trait Implementations§

Source§

impl Default for InternalClient

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more