Skip to content
QwryAI
Documentation
Pages

iOS SDK

QwryClient

The initializer, properties and methods of QwryClient, the main entry point of the QwryAI iOS SDK

public actor QwryClient

QwryClient talks to one QwryAI agent. Create it once and keep it. Because it's an actor, you can call it from any task, and its methods and mutable properties are reached with await.

init

Swift
public init(
    agentId: String,
    baseURL: URL = QwryClient.defaultBaseURL,
    configuration: URLSessionConfiguration = .default,
    maxToolLoopSteps: Int = 10
)
ParameterTypeDefaultDescription
agentIdStringRequiredYour agent's ID, from the Setup tab of the iOS SDK channel.
baseURLURLhttps://www.qwryai.com/api/sdkThe SDK API to call. Leave it at its default.
configurationURLSessionConfiguration.defaultThe session configuration used for every request. Set timeouts and caching here.
maxToolLoopStepsInt10How many rounds of tool calls one send or retry may make before it throws QwryError.toolLoopLimitExceeded. See Client-Side Tools.
Swift
// Custom timeouts
let config = URLSessionConfiguration.default
config.timeoutIntervalForRequest = 30
config.timeoutIntervalForResource = 300

let client = QwryClient(
    agentId: "YOUR_AGENT_ID",
    configuration: config,
    maxToolLoopSteps: 20
)

Properties

PropertyTypeDescription
agentIdStringThe agent this client talks to.
deviceIdStringThe device ID. Always available, without await.
authStateAuthState.anonymous, or .identified(userId:) after a successful identify.
currentConversationIdString?The conversation send continues. nil until the first answer, and after newConversation(), identify or logout.
currentUserIdString?The signed-in user's ID, or nil while anonymous.

The type also has two static values: QwryClient.version ("0.1.0") and QwryClient.defaultBaseURL.

Methods

MethodDescription
send(_:conversationId:configure:)Send a message, stream the answer and run tools. See Streaming.
retry(conversationId:messageId:configure:)Ask the agent to answer again. See Streaming.
sendNonStreaming(_:conversationId:)Get the whole answer at once, with no handlers. Tools still run. See Streaming.
tool(_:handler:)Register a tool the agent can run on the device. See Client-Side Tools.
removeTool(_:)Stop handling a tool. See Client-Side Tools.
identify(token:)Sign a user in with a JWT; returns their user ID. See User Identity.
logout()Go back to anonymous. See User Identity.
newConversation()Clear currentConversationId. See Conversations & History.
listConversations(cursor:limit:)List past conversations. See Conversations & History.
listMessages(conversationId:cursor:limit:)Load a page of a conversation's messages. See Conversations & History.

Explore the documentation