xllm_event_fn类型
One streaming event; the union payload is selected by kind.
extern "C" { #endif #define XLLM_VERSION_MAJOR 3 #define XLLM_VERSION_MINOR 0 #define XLLM_VERSION_PATCH 0 typedef struct xllm_client xllm_client; typedef struct xllm_call xllm_call; typedef struct xllm_hooks xllm_hooks; typedef struct xcancel xcancel; typedef struct xllm_request xllm_request; typedef struct xnetengine xnetengine; typedef struct xfuture xfuture; typedef struct xx509store xx509store; typedef enum xllm_result { XLLM_RESULT_OK = 0, XLLM_RESULT_ERROR = -1, XLLM_RESULT_TIMEOUT = -2, XLLM_RESULT_CANCELLED = -3 } xllm_result; typedef enum xllm_error_code { XLLM_ERROR_NONE = 0, XLLM_ERROR_INVALID_ARGUMENT, XLLM_ERROR_OUT_OF_MEMORY, XLLM_ERROR_NETWORK, XLLM_ERROR_TIMEOUT, XLLM_ERROR_CANCELLED, XLLM_ERROR_AUTH, XLLM_ERROR_RATE_LIMIT, XLLM_ERROR_MODEL_NOT_FOUND, XLLM_ERROR_UPSTREAM, XLLM_ERROR_PROTOCOL, XLLM_ERROR_PARSE, XLLM_ERROR_LIMIT, XLLM_ERROR_HOOK } xllm_error_code; typedef struct xllm_diagnostics { uint32_t uAttemptCount; uint32_t uMaxAttempts; uint32_t uRetryAfterMs; bool bRetryable; bool bRetryExhausted; bool bResponseStarted; bool bModelDataDelivered; bool bReusedConnection; bool bContextAttached; bool bToolCallDropped; int32_t iTransportStatus; int32_t iSystemError; uint64_t uStartedMs; uint64_t uConnectedMs; uint64_t uRequestSentMs; uint64_t uFirstByteMs; uint64_t uFirstTokenMs; uint64_t uHeadersMs; uint64_t uCompletedMs; uint64_t uConnectDurationMs; uint64_t uTimeToFirstByteMs; uint64_t uTransferDurationMs; uint64_t uTotalDurationMs; uint64_t uRequestBytes; uint64_t uResponseBodyBytes; uint64_t uContextDeadlineMs; int64 uEffectiveTimeoutMs; char sTransportError[32]; char sTransportPhase[32]; char sContextStatus[32]; char sDialect[24]; } xllm_diagnostics; typedef struct xllm_error { xllm_error_code eCode; int32_t iTransportStatus; int32_t iHttpStatus; char sMessage[512]; char sProviderMessage[2048]; char sProviderCode[64]; char sProviderType[64]; char sRequestId[160]; xllm_diagnostics tDiagnostics; } xllm_error; typedef enum xllm_role { XLLM_ROLE_SYSTEM = 0, XLLM_ROLE_USER, XLLM_ROLE_ASSISTANT, XLLM_ROLE_TOOL } xllm_role; typedef enum xllm_provider { XLLM_PROVIDER_OPENAI_COMPAT = 0, XLLM_PROVIDER_GLM, XLLM_PROVIDER_OPENAI_RESPONSES, XLLM_PROVIDER_ANTHROPIC } xllm_provider; typedef enum xllm_part_kind { XLLM_PART_TEXT = 0, XLLM_PART_REASONING, XLLM_PART_IMAGE, XLLM_PART_AUDIO, XLLM_PART_FILE, XLLM_PART_NATIVE } xllm_part_kind; typedef struct xllm_part { xllm_part_kind eKind; char* sText; char* sNativeType; char* sMediaType; char* sSourceUrl; char* sDetail; uint8_t* pData; size_t iDataSize; } xllm_part; XRT_API void xllmPartInit(xllm_part* pPart, xllm_part_kind eKind); XRT_API void xllmPartUnit(xllm_part* pPart); XRT_API bool xllmPartSetText(xllm_part* pPart, const char* sText); XRT_API bool xllmPartSetImageData(xllm_part* pPart, const void* pData, size_t iSize, const char* sMediaType); XRT_API bool xllmPartSetImageUrl(xllm_part* pPart, const char* sUrl, const char* sMediaType); XRT_API bool xllmPartSetAudioData(xllm_part* pPart, const void* pData, size_t iSize, const char* sMediaType); XRT_API bool xllmPartSetFileData(xllm_part* pPart, const void* pData, size_t iSize, const char* sMediaType); XRT_API bool xllmPartSetNative(xllm_part* pPart, const char* sNativeType, const char* sJson); typedef struct xllm_tool_call { char* sId; char* sName; char* sArgumentsJson; } xllm_tool_call; typedef struct xllm_message { xllm_role eRole; char* sContent; char* sReasoningContent; char* sToolCallId; xllm_tool_call* pToolCalls; size_t iToolCallCount; size_t iToolCallCap; xllm_part* pParts; size_t iPartCount; size_t iPartCap; char* sNative; } xllm_message; typedef struct xllm_tool { char* sName; char* sDescription; char* sParametersJson; bool bStrict; } xllm_tool; typedef enum xllm_tool_choice { XLLM_TOOL_CHOICE_AUTO = 0, XLLM_TOOL_CHOICE_NONE, XLLM_TOOL_CHOICE_REQUIRED, XLLM_TOOL_CHOICE_NAMED } xllm_tool_choice; typedef struct xllm_usage { uint64_t uInputTokens; uint64_t uOutputTokens; uint64_t uTotalTokens; uint64_t uCachedInputTokens; uint64_t uCacheWriteTokens; uint64_t uReasoningTokens; } xllm_usage; typedef enum xllm_finish { XLLM_FINISH_STOP = 0, XLLM_FINISH_LENGTH, XLLM_FINISH_TOOL_CALLS, XLLM_FINISH_CONTENT_FILTER, XLLM_FINISH_REFUSAL, XLLM_FINISH_OTHER } xllm_finish; typedef enum xllm_block_kind { XLLM_BLOCK_TEXT = 0, XLLM_BLOCK_REASONING, XLLM_BLOCK_TOOL_CALL } xllm_block_kind; typedef struct xllm_block { xllm_block_kind eKind; char* sText; size_t iToolIndex; char* sNative; } xllm_block; typedef struct xllm_stats { xllm_usage tUsage; uint64_t uConnectMs; uint64_t uFirstByteMs; uint64_t uFirstTokenMs; uint64_t uTotalMs; double fOutputTokensPerSec; uint64_t uRequestBytes; uint64_t uResponseBytes; uint32_t uAttempts; bool bReusedConnection; } xllm_stats; typedef struct xllm_response { char* sId; char* sModel; char* sContent; char* sReasoningContent; char* sRefusal; char* sFinishReason; xllm_finish eFinish; char* sRequestId; xllm_block* pBlocks; size_t iBlockCount; xllm_tool_call* pToolCalls; size_t iToolCallCount; size_t iToolCallCap; xllm_usage tUsage; uint32_t uHttpStatus; xllm_diagnostics tDiagnostics; xllm_stats tStats; } xllm_response; typedef enum xllm_event_kind { XLLM_EVENT_RESPONSE_START = 0, XLLM_EVENT_TEXT_DELTA, XLLM_EVENT_REASONING_DELTA, XLLM_EVENT_TOOL_CALL_DELTA, XLLM_EVENT_BLOCK_META, XLLM_EVENT_USAGE, XLLM_EVENT_RESPONSE_DONE } xllm_event_kind; typedef struct xllm_event { xllm_event_kind eKind; union { struct { size_t iBlock; const char* sData; size_t iLen; } tText; struct { size_t iIndex; size_t iBlock; const char* sIdDelta; const char* sNameDelta; const char* sArgumentsDelta; } tToolCall; struct { size_t iBlock; xllm_block_kind eKind; bool bEnd; } tBlockMeta; xllm_usage tUsage; struct { uint32_t uHttpStatus; const char* sRequestId; } tResponse; } as; } xllm_event; typedef bool (*xllm_event_fn)(void* pUserData, const xllm_event* pEvent); typedef struct xllm_stream_callbacks { void* pUserData; xllm_event_fn OnEvent; } xllm_stream_callbacks; typedef uint64_t xllm_capability_flags; #define XLLM_CAP_TEXT_IN (1ull << 0) #define XLLM_CAP_TOOL_RESULT_IN (1ull << 1) #define XLLM_CAP_TEXT_OUT (1ull << 2) #define XLLM_CAP_JSON_OUT (1ull << 3) #define XLLM_CAP_TOOL_CALL_OUT (1ull << 4) #define XLLM_CAP_REASONING_OUT (1ull << 5) #define XLLM_CAP_STREAM (1ull << 6) #define XLLM_CAP_REASONING_CONTROL (1ull << 7) #define XLLM_CAP_PARALLEL_TOOL_CALL (1ull << 8) #define XLLM_CAP_MAX_COMPLETION_TOKENS (1ull << 9) #define XLLM_CAP_DEVELOPER_ROLE (1ull << 10) #define XLLM_CAP_IMAGE_IN (1ull << 11) typedef enum xllm_window_mode { XLLM_WINDOW_UNSPECIFIED = 0, XLLM_WINDOW_SHARED_CONTEXT, XLLM_WINDOW_SPLIT_INPUT_OUTPUT } xllm_window_mode; typedef struct xllm_model_profile { const char* sId; const char* sModel; xllm_provider eProvider; xllm_capability_flags uCapabilities; xllm_window_mode eWindowMode; uint64_t uContextWindowTokens; uint64_t uMaxInputTokens; uint32_t uMaxOutputTokens; uint32_t uRecommendedOutputReserveTokens; uint32_t uRecommendedSummaryTokens; } xllm_model_profile; XRT_API void xllmModelProfileInit(xllm_model_profile* pProfile); XRT_API const xllm_model_profile* xllmModelProfileBuiltin(const char* sIdOrModel); XRT_API bool xllmModelProfileValidate(const xllm_model_profile* pProfile, xllm_error* pError); XRT_API bool xllmModelProfileSupports(const xllm_model_profile* pProfile, xllm_capability_flags uRequired); XRT_API bool xllmModelProfileValidateRequest(const xllm_model_profile* pProfile, const xllm_request* pRequest, xllm_error* pError); XRT_API void xllmErrorInit(xllm_error* pError); XRT_API const char* xllmErrorCodeName(xllm_error_code eCode); XRT_API const char* xllmFinishReasonName(xllm_finish eFinish); XRT_API bool xllmErrorRetryable(const xllm_error* pError); XRT_API void xllmMessageInit(xllm_message* pMessage, xllm_role eRole); XRT_API void xllmMessageUnit(xllm_message* pMessage); XRT_API bool xllmMessageSetContent(xllm_message* pMessage, const char* sContent); XRT_API bool xllmMessageSetReasoning(xllm_message* pMessage, const char* sReasoningContent); XRT_API bool xllmMessageSetToolCallId(xllm_message* pMessage, const char* sToolCallId); XRT_API bool xllmMessageAddToolCall(xllm_message* pMessage, const char* sId, const char* sName, const char* sArgumentsJson); XRT_API bool xllmMessageAddPart(xllm_message* pMessage, const xllm_part* pPart); XRT_API bool xllmMessageSetNative(xllm_message* pMessage, const char* sNativeJson); XRT_API bool xllmMessageFromResponse(const xllm_response* pResponse, xllm_message* pMessage); typedef enum xllm_json_mode { XLLM_JSON_NONE = 0, XLLM_JSON_OBJECT } xllm_json_mode; typedef struct xllm_header { const char* sName; const char* sValue; } xllm_header; typedef struct xllm_request { xllm_message* pMessages; size_t iMessageCount; size_t iMessageCap; xllm_tool* pTools; size_t iToolCount; size_t iToolCap; bool* pbMessageBorrowed; bool* pbToolBorrowed; char* sModel; char* sReasoningEffort; char* sNamedTool; uint32_t uReasoningBudgetTokens; uint32_t uMaxOutputTokens; double fTemperature; bool bHasTemperature; double fTopP; bool bHasTopP; char* sStop; bool bParallelToolCalls; xllm_tool_choice eToolChoice; xllm_json_mode eJsonMode; bool bStream; const xllm_header* pExtraHeaders; size_t iExtraHeaderCount; char* sExtraBodyJson; xcancel* pCancel; int64_t iTimeout; const xllm_hooks* pHooks; void* pStablePrefixOwner; uint64_t uStablePrefixStamp; size_t iStableMessages; } xllm_request; XRT_API void xllmRequestInit(xllm_request* pRequest); XRT_API void xllmRequestUnit(xllm_request* pRequest); XRT_API bool xllmRequestAddMessageView(xllm_request* pRequest, const xllm_message* pMessage); XRT_API bool xllmRequestSetToolsView(xllm_request* pRequest, const xllm_tool* pTools, size_t iCount); XRT_API bool xllmRequestSetModel(xllm_request* pRequest, const char* sModel); XRT_API bool xllmRequestSetReasoningEffort(xllm_request* pRequest, const char* sEffort); XRT_API bool xllmRequestSetStop(xllm_request* pRequest, const char* sStop); XRT_API bool xllmRequestSetExtraBody(xllm_request* pRequest, const char* sJsonObject); XRT_API void xllmRequestSetCancel(xllm_request* pRequest, xcancel* pCancel); XRT_API void xllmRequestSetTimeout(xllm_request* pRequest, int64_t iTimeout); XRT_API bool xllmRequestSetToolChoice(xllm_request* pRequest, xllm_tool_choice eChoice, const char* sNamedTool); XRT_API bool xllmRequestAddMessage(xllm_request* pRequest, const xllm_message* pMessage); XRT_API bool xllmRequestAddTextMessage(xllm_request* pRequest, xllm_role eRole, const char* sContent); XRT_API bool xllmRequestAddToolResult(xllm_request* pRequest, const char* sToolCallId, const char* sContent); XRT_API bool xllmRequestAddTool(xllm_request* pRequest, const char* sName, const char* sDescription, const char* sParametersJson, bool bStrict); XRT_API void xllmResponseDestroy(xllm_response* pResponse); XRT_API uint64_t xllmEstimateTextTokens(const char* sText); XRT_API uint64_t xllmEstimateMessageTokens(const xllm_message* pMessage); typedef struct xllm_wire { uint32_t uAttempt; uint32_t uHttpStatus; char* sBody; size_t iBodySize; size_t iBodyCapacity; uint32_t uReserved[4]; } xllm_wire; struct xllm_hooks { bool (*pOnRequest)(xllm_client* pClient, xllm_request* pRequest, void* pUserData); bool (*pOnRequestBody)(xllm_client* pClient, xllm_wire* pWire, void* pUserData); bool (*pOnRetry)(xllm_client* pClient, const xllm_diagnostics* pDiagnostics, uint32_t uNextAttempt, void* pUserData); bool (*pOnResponseBody)(xllm_client* pClient, xllm_wire* pWire, void* pUserData); bool (*pOnToolCall)(xllm_client* pClient, xllm_tool_call* pCall, uint32_t uIndex, void* pUserData); bool (*pOnResponse)(xllm_client* pClient, xllm_response* pResponse, void* pUserData); void* pUserData; uint32_t uReserved[4]; }; XRT_API void xllmClientSetHooks(xllm_client* pClient, const xllm_hooks* pHooks); typedef struct xllm_history xllm_history; XRT_API xllm_history* xllmHistoryCreate(void); XRT_API void xllmHistoryDestroy(xllm_history* pHistory); XRT_API size_t xllmHistoryCount(const xllm_history* pHistory); XRT_API const xllm_message* xllmHistoryAt(const xllm_history* pHistory, size_t iIndex); XRT_API bool xllmHistoryAdd(xllm_history* pHistory, const xllm_message* pMessage); XRT_API bool xllmHistoryAddText(xllm_history* pHistory, xllm_role eRole, const char* sContent); XRT_API bool xllmHistoryAddFromResponse(xllm_history* pHistory, const xllm_response* pResponse); XRT_API bool xllmHistoryAddToolResult(xllm_history* pHistory, const char* sCallId, const char* sContent); XRT_API bool xllmHistoryRemove(xllm_history* pHistory, size_t iIndex, size_t iCount); XRT_API bool xllmHistoryAppendInto(const xllm_history* pHistory, xllm_request* pRequest); typedef struct xllm_client_config { const char* sBaseUrl; const char* sApiKey; const char* sModel; const char* sReasoningEffort; const char* sUserAgent; uint32_t uMaxOutputTokens; uint32_t uTimeoutMs; uint32_t uIdleTimeoutMs; uint32_t uMaxAttempts; uint32_t uRetryBaseDelayMs; uint32_t uRetryMaxDelayMs; uint32_t uMaxIdleConnections; xnetengine* pNetEngine; bool bVerifyPeer; const char* sCaPem; xx509store* pX509Store; xllm_provider eProvider; const xllm_model_profile* pModelProfile; } xllm_client_config; XRT_API void xllmClientConfigInit(xllm_client_config* pConfig); XRT_API xllm_client* xllmClientCreate(const xllm_client_config* pConfig, xllm_error* pError); XRT_API void xllmClientSetHooks(xllm_client* pClient, const xllm_hooks* pHooks); XRT_API void xllmClientDestroy(xllm_client* pClient); XRT_API bool xllmClientGetModelProfile(const xllm_client* pClient, xllm_model_profile* pProfile); XRT_API bool xllmClientSetModelProfile(xllm_client* pClient, const xllm_model_profile* pProfile, xllm_error* pError); XRT_API xllm_call* xllmClientStart( xllm_client* pClient, const xllm_request* pRequest, const xllm_stream_callbacks* pCallbacks, xllm_error* pError ); XRT_API xfuture* xllmCallFuture(xllm_call* pCall); XRT_API xllm_result xllmCallWait(xllm_call* pCall, xllm_response** ppResponse, xllm_error* pError); XRT_API bool xllmCallCancel(xllm_call* pCall); XRT_API void xllmCallDestroy(xllm_call* pCall); XRT_API xllm_result xllmClientComplete( xllm_client* pClient, const xllm_request* pRequest, const xllm_stream_callbacks* pCallbacks, xllm_response** ppResponse, xllm_error* pError ); XRT_API char* xllmClientBuildRequestJson(xllm_client* pClient, const xllm_request* pRequest, xllm_error* pError); XRT_API void xllmFree(void* pMemory)
XLLM_RESULT_OK常量
契约注释见公共头文件。
XLLM_RESULT_OK
XLLM_RESULT_ERROR常量
契约注释见公共头文件。
XLLM_RESULT_ERROR
XLLM_RESULT_TIMEOUT常量
契约注释见公共头文件。
XLLM_RESULT_TIMEOUT
XLLM_RESULT_CANCELLED常量
契约注释见公共头文件。
XLLM_RESULT_CANCELLED
XLLM_ERROR_NONE常量
契约注释见公共头文件。
XLLM_ERROR_NONE
XLLM_ERROR_INVALID_ARGUMENT常量
契约注释见公共头文件。
XLLM_ERROR_INVALID_ARGUMENT
XLLM_ERROR_OUT_OF_MEMORY常量
契约注释见公共头文件。
XLLM_ERROR_OUT_OF_MEMORY
XLLM_ERROR_NETWORK常量
契约注释见公共头文件。
XLLM_ERROR_NETWORK
XLLM_ERROR_TIMEOUT常量
契约注释见公共头文件。
XLLM_ERROR_TIMEOUT
XLLM_ERROR_CANCELLED常量
契约注释见公共头文件。
XLLM_ERROR_CANCELLED
XLLM_ERROR_AUTH常量
契约注释见公共头文件。
XLLM_ERROR_AUTH
XLLM_ERROR_RATE_LIMIT常量
契约注释见公共头文件。
XLLM_ERROR_RATE_LIMIT
XLLM_ERROR_MODEL_NOT_FOUND常量
契约注释见公共头文件。
XLLM_ERROR_MODEL_NOT_FOUND
XLLM_ERROR_UPSTREAM常量
契约注释见公共头文件。
XLLM_ERROR_UPSTREAM
XLLM_ERROR_PROTOCOL常量
契约注释见公共头文件。
XLLM_ERROR_PROTOCOL
XLLM_ERROR_PARSE常量
契约注释见公共头文件。
XLLM_ERROR_PARSE
XLLM_ERROR_LIMIT常量
契约注释见公共头文件。
XLLM_ERROR_LIMIT
XLLM_ERROR_HOOK常量
契约注释见公共头文件。
XLLM_ERROR_HOOK
XLLM_ROLE_SYSTEM常量
契约注释见公共头文件。
XLLM_ROLE_SYSTEM
XLLM_ROLE_USER常量
契约注释见公共头文件。
XLLM_ROLE_USER
XLLM_ROLE_ASSISTANT常量
契约注释见公共头文件。
XLLM_ROLE_ASSISTANT
XLLM_PROVIDER_OPENAI_COMPAT常量
契约注释见公共头文件。
XLLM_PROVIDER_OPENAI_COMPAT
XLLM_PROVIDER_GLM常量
契约注释见公共头文件。
XLLM_PROVIDER_GLM
XLLM_PROVIDER_OPENAI_RESPONSES常量
契约注释见公共头文件。
XLLM_PROVIDER_OPENAI_RESPONSES
XLLM_PROVIDER_ANTHROPIC常量
契约注释见公共头文件。
XLLM_PROVIDER_ANTHROPIC
XLLM_PART_TEXT常量
契约注释见公共头文件。
XLLM_PART_TEXT
XLLM_PART_REASONING常量
契约注释见公共头文件。
XLLM_PART_REASONING
XLLM_PART_IMAGE常量
契约注释见公共头文件。
XLLM_PART_IMAGE
XLLM_PART_AUDIO常量
契约注释见公共头文件。
XLLM_PART_AUDIO
XLLM_PART_FILE常量
契约注释见公共头文件。
XLLM_PART_FILE
XLLM_PART_NATIVE常量
契约注释见公共头文件。
XLLM_PART_NATIVE
XLLM_FINISH_STOP常量
契约注释见公共头文件。
XLLM_FINISH_STOP
XLLM_FINISH_LENGTH常量
契约注释见公共头文件。
XLLM_FINISH_LENGTH
XLLM_FINISH_CONTENT_FILTER常量
契约注释见公共头文件。
XLLM_FINISH_CONTENT_FILTER
XLLM_FINISH_REFUSAL常量
契约注释见公共头文件。
XLLM_FINISH_REFUSAL
XLLM_FINISH_OTHER常量
契约注释见公共头文件。
XLLM_FINISH_OTHER
XLLM_BLOCK_TEXT常量
契约注释见公共头文件。
XLLM_BLOCK_TEXT
XLLM_BLOCK_REASONING常量
契约注释见公共头文件。
XLLM_BLOCK_REASONING
XLLM_EVENT_RESPONSE_START常量
契约注释见公共头文件。
XLLM_EVENT_RESPONSE_START
XLLM_EVENT_TEXT_DELTA常量
契约注释见公共头文件。
XLLM_EVENT_TEXT_DELTA
XLLM_EVENT_REASONING_DELTA常量
契约注释见公共头文件。
XLLM_EVENT_REASONING_DELTA
XLLM_EVENT_USAGE常量
契约注释见公共头文件。
XLLM_EVENT_USAGE
XLLM_EVENT_RESPONSE_DONE常量
契约注释见公共头文件。
XLLM_EVENT_RESPONSE_DONE
XLLM_WINDOW_UNSPECIFIED常量
契约注释见公共头文件。
XLLM_WINDOW_UNSPECIFIED
XLLM_WINDOW_SHARED_CONTEXT常量
契约注释见公共头文件。
XLLM_WINDOW_SHARED_CONTEXT
XLLM_JSON_NONE常量
契约注释见公共头文件。
XLLM_JSON_NONE
XLLM_JSON_OBJECT常量
契约注释见公共头文件。
XLLM_JSON_OBJECT
xllm_result类型
Call outcome (ok / error / timeout / cancelled).
typedef enum xllm_result { ... } xllm_result;
xllm_error_code类型
Stable error categories (argument, OOM, network, protocol, auth, ...).
typedef enum xllm_error_code { ... } xllm_error_code;
xllm_diagnostics类型
Retry diagnostics (attempt, limit, retry-after, retryable).
typedef struct xllm_diagnostics { ... } xllm_diagnostics;
xllm_error类型
Full error detail with transport and HTTP status plus message.
typedef struct xllm_error { ... } xllm_error;
xllm_role类型
Chat roles (system, user, assistant, tool).
typedef enum xllm_role { ... } xllm_role;
xllm_provider类型
Wire dialect selection (OpenAI-compatible, GLM, Responses, Anthropic).
typedef enum xllm_provider { ... } xllm_provider;
xllm_part_kind类型
Multimodal part kinds (text, reasoning, image, audio, file, native).
typedef enum xllm_part_kind { ... } xllm_part_kind;
xllm_part类型
One multimodal part; fields are owned copies set by the Set* helpers.
typedef struct xllm_part { ... } xllm_part;
xllm_message类型
A chat message: role, text fast path, reasoning, tool calls, parts.
typedef struct xllm_message { ... } xllm_message;
xllm_usage类型
Token usage reported by the provider (input, output, cached, reasoning).
typedef struct xllm_usage { ... } xllm_usage;
xllm_finish类型
Why generation stopped (stop, length, tool calls, content filter).
typedef enum xllm_finish { ... } xllm_finish;
xllm_block_kind类型
Response block kinds (text, reasoning, tool call) in arrival order.
typedef enum xllm_block_kind { ... } xllm_block_kind;
xllm_block类型
Responses arrive as ordered blocks so callers can render interleaved
typedef struct xllm_block { ... } xllm_block;
xllm_stats类型
Call statistics: usage plus timing milestones and byte counts.
typedef struct xllm_stats { ... } xllm_stats;
xllm_response类型
Owned response: joined text plus ordered blocks and tool calls.
typedef struct xllm_response { ... } xllm_response;
xllm_event_kind类型
Streaming event kinds (response start, deltas, tool arguments, usage, done).
typedef enum xllm_event_kind { ... } xllm_event_kind;
xllm_event类型
One streaming event; the union payload is selected by kind.
typedef struct xllm_event { ... } xllm_event;
xllm_stream_callbacks类型
Stream callbacks fire on the client engine's background workers, never on
typedef struct xllm_stream_callbacks { ... } xllm_stream_callbacks;
xllm_window_mode类型
Context window shape (shared context vs split input/output).
typedef enum xllm_window_mode { ... } xllm_window_mode;
xllm_model_profile类型
A model profile is a non-secret, inspectable capability contract. Connection
typedef struct xllm_model_profile { ... } xllm_model_profile;
xllm_json_mode类型
JSON response mode (off or object).
typedef enum xllm_json_mode { ... } xllm_json_mode;
xllm_request类型
Owned request: messages, tools, sampling, budgets, cancellation.
typedef struct xllm_request { ... } xllm_request;
xllm_wire类型
Wire-level body handed to the byte seams. The buffer is NUL-terminated;
typedef struct xllm_wire { ... } xllm_wire;
xllm_client_config类型
Client setup: base URL, key, model, dialect, timeouts, retry policy.
typedef struct xllm_client_config { ... } xllm_client_config;
xllmPartInit函数
Zero-init a part of the given kind; fill it with the xllmPartSet* helpers.
XRT_API void xllmPartInit(xllm_part* pPart, xllm_part_kind eKind)
xllmPartUnit函数
Release a part constructed with the xllmPartSet* helpers (deep frees).
XRT_API void xllmPartUnit(xllm_part* pPart)
xllmPartSetText函数
Set plain-text content; the string is copied.
XRT_API bool xllmPartSetText(xllm_part* pPart, const char* sText)
xllmPartSetImageData函数
Attach inline image bytes (copied); mediaType e.g. "image/png".
XRT_API bool xllmPartSetImageData(xllm_part* pPart, const void* pData, size_t iSize, const char* sMediaType)
xllmPartSetImageUrl函数
Attach an image by remote URL; mediaType e.g. "image/jpeg".
XRT_API bool xllmPartSetImageUrl(xllm_part* pPart, const char* sUrl, const char* sMediaType)
xllmPartSetAudioData函数
Attach inline audio bytes (copied); mediaType e.g. "audio/wav".
XRT_API bool xllmPartSetAudioData(xllm_part* pPart, const void* pData, size_t iSize, const char* sMediaType)
xllmPartSetFileData函数
Attach inline file bytes (copied); mediaType carries the document type.
XRT_API bool xllmPartSetFileData(xllm_part* pPart, const void* pData, size_t iSize, const char* sMediaType)
xllmPartSetNative函数
Attach a provider-native part (raw JSON); replayed verbatim on the wire.
XRT_API bool xllmPartSetNative(xllm_part* pPart, const char* sNativeType, const char* sJson)
xllmModelProfileInit函数
Fill a model profile with safe defaults (no caps, no limits).
XRT_API void xllmModelProfileInit(xllm_model_profile* pProfile)
xllmModelProfileBuiltin函数
Look up a built-in profile by id or model name; NULL when unknown.
XRT_API const xllm_model_profile* xllmModelProfileBuiltin(const char* sIdOrModel)
xllmModelProfileValidate函数
Validate profile consistency (limits and caps); fills pError on failure.
XRT_API bool xllmModelProfileValidate(const xllm_model_profile* pProfile, xllm_error* pError)
xllmModelProfileSupports函数
Test whether the profile declares every required capability bit.
XRT_API bool xllmModelProfileSupports(const xllm_model_profile* pProfile, xllm_capability_flags uRequired)
xllmModelProfileValidateRequest函数
Validate a request against the profile (model, tools, modalities, budgets).
XRT_API bool xllmModelProfileValidateRequest(const xllm_model_profile* pProfile, const xllm_request* pRequest, xllm_error* pError)
xllmErrorInit函数
Zero an error struct; reusable across failure paths.
XRT_API void xllmErrorInit(xllm_error* pError)
xllmErrorCodeName函数
Stable name for an error code (never NULL).
XRT_API const char* xllmErrorCodeName(xllm_error_code eCode)
xllmFinishReasonName函数
Stable name for a finish reason (never NULL).
XRT_API const char* xllmFinishReasonName(xllm_finish eFinish)
xllmErrorRetryable函数
Whether a call failed with this error may be retried per transport policy.
XRT_API bool xllmErrorRetryable(const xllm_error* pError)
xllmMessageInit函数
Start a message with the given role; add content via the Set and Add helpers.
XRT_API void xllmMessageInit(xllm_message* pMessage, xllm_role eRole)
xllmMessageUnit函数
Deep-free a message (parts, strings, tool calls).
XRT_API void xllmMessageUnit(xllm_message* pMessage)
xllmMessageSetContent函数
Replace the text content; copied, fails only on OOM.
XRT_API bool xllmMessageSetContent(xllm_message* pMessage, const char* sContent)
xllmMessageSetReasoning函数
Set the reasoning text captured from thinking models; copied.
XRT_API bool xllmMessageSetReasoning(xllm_message* pMessage, const char* sReasoningContent)
xllmMessageAddPart函数
Append a multimodal part; deep-copied.
XRT_API bool xllmMessageAddPart(xllm_message* pMessage, const xllm_part* pPart)
xllmMessageSetNative函数
Replace with a provider-native message body (raw JSON, replayed verbatim).
XRT_API bool xllmMessageSetNative(xllm_message* pMessage, const char* sNativeJson)
xllmMessageFromResponse函数
Convenience: build a history assistant message from a completed response
XRT_API bool xllmMessageFromResponse(const xllm_response* pResponse, xllm_message* pMessage)
xllmRequestInit函数
Zero a request and apply defaults; Unit frees everything it owns.
XRT_API void xllmRequestInit(xllm_request* pRequest)
xllmRequestUnit函数
Deep-free the request contents (messages, tools, strings).
XRT_API void xllmRequestUnit(xllm_request* pRequest)
xllmRequestAddMessageView函数
Shallow-append a message whose strings the lender owns (ledger entries,
XRT_API bool xllmRequestAddMessageView(xllm_request* pRequest, const xllm_message* pMessage)
xllmRequestSetModel函数
Override the model id; copied.
XRT_API bool xllmRequestSetModel(xllm_request* pRequest, const char* sModel)
xllmRequestSetReasoningEffort函数
Set reasoning effort ("low"/"medium"/"high").
XRT_API bool xllmRequestSetReasoningEffort(xllm_request* pRequest, const char* sEffort)
xllmRequestSetStop函数
Add a stop sequence (within the provider limit); copied.
XRT_API bool xllmRequestSetStop(xllm_request* pRequest, const char* sStop)
xllmRequestSetExtraBody函数
Merge a JSON object into the wire body (top-level keys, shallow).
XRT_API bool xllmRequestSetExtraBody(xllm_request* pRequest, const char* sJsonObject)
xllmRequestSetCancel函数
Bind a cancel token consulted during the call; borrowed.
XRT_API void xllmRequestSetCancel(xllm_request* pRequest, xcancel* pCancel)
xllmRequestSetTimeout函数
Per-call timeout in ms overriding the client default (0 keeps the default).
XRT_API void xllmRequestSetTimeout(xllm_request* pRequest, int64_t iTimeout)
xllmRequestAddMessage函数
Append a full message; deep-copied.
XRT_API bool xllmRequestAddMessage(xllm_request* pRequest, const xllm_message* pMessage)
xllmRequestAddTextMessage函数
Convenience: append a text-only message.
XRT_API bool xllmRequestAddTextMessage(xllm_request* pRequest, xllm_role eRole, const char* sContent)
xllmResponseDestroy函数
Free a response and everything it owns.
XRT_API void xllmResponseDestroy(xllm_response* pResponse)
xllmEstimateTextTokens函数
Deterministic lexical token estimates used by budget governance.
XRT_API uint64_t xllmEstimateTextTokens(const char* sText)
xllmEstimateMessageTokens函数
Rough token estimate for budget checks; no model call.
XRT_API uint64_t xllmEstimateMessageTokens(const xllm_message* pMessage)
xllmClientSetHooks函数
Client-level default hooks (borrowed struct; NULL removes). A request may
XRT_API void xllmClientSetHooks(xllm_client* pClient, const xllm_hooks* pHooks)
xllmHistoryCreate函数
Create an empty owned message history.
XRT_API xllm_history* xllmHistoryCreate()
xllmHistoryDestroy函数
Free the history.
XRT_API void xllmHistoryDestroy(xllm_history* pHistory)
xllmHistoryCount函数
Number of stored messages.
XRT_API size_t xllmHistoryCount(const xllm_history* pHistory)
xllmHistoryAt函数
Borrowed view of one stored message; valid until the next mutation.
XRT_API const xllm_message* xllmHistoryAt(const xllm_history* pHistory, size_t iIndex)
xllmHistoryAdd函数
Append a deep copy of the message.
XRT_API bool xllmHistoryAdd(xllm_history* pHistory, const xllm_message* pMessage)
xllmHistoryAddText函数
Convenience: append a text-only message.
XRT_API bool xllmHistoryAddText(xllm_history* pHistory, xllm_role eRole, const char* sContent)
xllmHistoryAddFromResponse函数
Text + reasoning + tool calls from a completed response.
XRT_API bool xllmHistoryAddFromResponse(xllm_history* pHistory, const xllm_response* pResponse)
xllmHistoryAddToolResult函数
Convenience: append a tool-result message.
XRT_API bool xllmHistoryAddToolResult(xllm_history* pHistory, const char* sCallId, const char* sContent)
xllmHistoryRemove函数
Remove iCount messages starting at iIndex; the tail shifts down.
XRT_API bool xllmHistoryRemove(xllm_history* pHistory, size_t iIndex, size_t iCount)
xllmHistoryAppendInto函数
Appends every stored message into a request (deep copy again).
XRT_API bool xllmHistoryAppendInto(const xllm_history* pHistory, xllm_request* pRequest)
xllmClientConfigInit函数
Zero a client config with defaults (30-minute timeout, retry enabled).
XRT_API void xllmClientConfigInit(xllm_client_config* pConfig)
xllmClientCreate函数
Create a client; fills pError and returns NULL on failure.
XRT_API xllm_client* xllmClientCreate(const xllm_client_config* pConfig, xllm_error* pError)
xllmClientDestroy函数
Destroy the client; in-flight calls must be finished first.
XRT_API void xllmClientDestroy(xllm_client* pClient)
xllmClientGetModelProfile函数
Copy out the effective, config-resolved model profile.
XRT_API bool xllmClientGetModelProfile(const xllm_client* pClient, xllm_model_profile* pProfile)
xllmClientSetModelProfile函数
Replace the client's capability profile on an existing client (custom
XRT_API bool xllmClientSetModelProfile(xllm_client* pClient, const xllm_model_profile* pProfile, xllm_error* pError)
xllmClientStart函数
Submit a call asynchronously; returns the call and a borrowed future, or NULL with pError.
XRT_API xllm_call* xllmClientStart(xllm_client* pClient, const xllm_request* pRequest, const xllm_stream_callbacks* pCallbacks, xllm_error* pError)
xllmCallFuture函数
The call's completion future; transport runs on the engine workers.
XRT_API xfuture* xllmCallFuture(xllm_call* pCall)
xllmCallWait函数
Wait once for completion; yields the owned response via ppResponse.
XRT_API xllm_result xllmCallWait(xllm_call* pCall, xllm_response** ppResponse, xllm_error* pError)
xllmCallCancel函数
Request cooperative cancellation; safe to call after completion.
XRT_API bool xllmCallCancel(xllm_call* pCall)
xllmCallDestroy函数
Destroy the call handle after waiting or cancelling.
XRT_API void xllmCallDestroy(xllm_call* pCall)
xllmClientComplete函数
Blocking one-shot: start, wait, destroy; NULL response with pError on failure.
XRT_API xllm_result xllmClientComplete(xllm_client* pClient, const xllm_request* pRequest, const xllm_stream_callbacks* pCallbacks, xllm_response** ppResponse, xllm_error* pError)
xllmClientBuildRequestJson函数
Full classic serialization for inspection/testing; it never reads or
XRT_API char* xllmClientBuildRequestJson(xllm_client* pClient, const xllm_request* pRequest, xllm_error* pError)
xllmFree函数
Free memory returned by xllm (portable across allocator boundaries).
XRT_API void xllmFree(void* pMemory)
xllm_executor_ctx类型
Per-call execution context, supplied by whoever drives the loop.
typedef struct xllm_executor_ctx { ... } xllm_executor_ctx;
xllm_executor_result类型
One tool outcome. sContent must be presentable to the model as-is: the
typedef struct xllm_executor_result { ... } xllm_executor_result;