Expand description
Shared OpenAI wire-protocol HTTP layer.
Provides a provider-neutral implementation of the OpenAI REST protocol
suitable for any OpenAI-compatible API endpoint. Extracted from api_xai
and api_openai to eliminate infrastructure duplication.
§Features
enabled— activates all public types and the HTTP clientstreaming— Server-Sent Events streaming supportsync_api— blocking wrappers around the async clientintegration— real-API integration tests (requires live credentials)full— enablesenabled,streaming,sync_api, andintegration
§Architecture
Follows the “Thin Client, Rich API” principle: every method maps to exactly
one API endpoint, zero automatic decision-making, explicit control over all
operations. See docs/invariant/ at the workspace root for governing principles.
Modules§
- client
- Async HTTP client. Async HTTP client for OpenAI-compatible REST APIs.
- components
- Wire types for chat completion requests, responses, and streaming. OpenAI-compatible wire-type components.
- environment
- Environment configuration trait and default implementation. Environment configuration trait and default implementation.
- error
- Error type and result alias. Error type and result alias for OpenAI-compatible API operations.
- exposed
- Exposed namespace of the module.
- orphan
- Orphan namespace of the module.
- own
- Own namespace of the module.
- prelude
- Prelude to use essentials:
use my_module ::prelude :: *. - sync_
client - Blocking wrapper around the async client.
Blocking wrapper around
Clientfor synchronous contexts.
Structs§
- Chat
Completion Chunk - Wire types for chat completion requests, responses, and streaming. Server-Sent Events streaming types. Wire types for chat completion requests, responses, and streaming. Server-Sent Events streaming types. A single Server-Sent Events chunk from a streaming completion.
- Chat
Completion Request - Wire types for chat completion requests, responses, and streaming.
Chat completion request, response, and message types.
Wire types for chat completion requests, responses, and streaming.
Chat completion request, response, and message types.
Request body for the
POST chat/completionsendpoint. - Chat
Completion Response - Wire types for chat completion requests, responses, and streaming.
Chat completion request, response, and message types.
Wire types for chat completion requests, responses, and streaming.
Chat completion request, response, and message types.
Response body from the
POST chat/completionsendpoint. - Choice
- Wire types for chat completion requests, responses, and streaming.
Chat completion request, response, and message types.
Wire types for chat completion requests, responses, and streaming.
Chat completion request, response, and message types.
One completion alternative within a
ChatCompletionResponse. - Chunk
Choice - Wire types for chat completion requests, responses, and streaming. Server-Sent Events streaming types. Wire types for chat completion requests, responses, and streaming. Server-Sent Events streaming types. One delta choice within a streaming chunk.
- Client
- Async HTTP client. Async HTTP client. Async HTTP client for OpenAI-compatible REST APIs.
- Delta
- Wire types for chat completion requests, responses, and streaming. Server-Sent Events streaming types. Wire types for chat completion requests, responses, and streaming. Server-Sent Events streaming types. Partial message update delivered in a streaming chunk.
- Function
- Wire types for chat completion requests, responses, and streaming. Chat completion request, response, and message types. Wire types for chat completion requests, responses, and streaming. Chat completion request, response, and message types. Function specification (name, description, JSON Schema parameters).
- Function
Call - Wire types for chat completion requests, responses, and streaming. Chat completion request, response, and message types. Wire types for chat completion requests, responses, and streaming. Chat completion request, response, and message types. Name and arguments for a specific function invocation.
- Message
- Wire types for chat completion requests, responses, and streaming. Chat completion request, response, and message types. Wire types for chat completion requests, responses, and streaming. Chat completion request, response, and message types. A single message in a chat conversation.
- Open
AiCompat Environment Impl - Environment configuration trait and default implementation. Environment configuration trait and default implementation. Default OpenAI-compatible environment backed by in-memory values.
- Sync
Client - Blocking wrapper around the async client.
Blocking wrapper around the async client.
Blocking wrapper around
Clientfor use in synchronous contexts. - Tool
- Wire types for chat completion requests, responses, and streaming.
Chat completion request, response, and message types.
Wire types for chat completion requests, responses, and streaming.
Chat completion request, response, and message types.
A function tool definition passed in the
toolsarray of a request. - Tool
Call - Wire types for chat completion requests, responses, and streaming. Chat completion request, response, and message types. Wire types for chat completion requests, responses, and streaming. Chat completion request, response, and message types. A function invocation requested by the assistant.
- Usage
- Wire types for chat completion requests, responses, and streaming. Chat completion request, response, and message types. Wire types for chat completion requests, responses, and streaming. Chat completion request, response, and message types. Token usage statistics returned in every completion response.
Enums§
- Open
AiCompat Error - Error type and result alias. Error type and result alias. Error variants for OpenAI-compatible API operations.
- Role
- Wire types for chat completion requests, responses, and streaming. Chat completion request, response, and message types. Wire types for chat completion requests, responses, and streaming. Chat completion request, response, and message types. Role of a participant in a chat conversation.
Traits§
- Open
AiCompat Environment - Environment configuration trait and default implementation. Environment configuration trait and default implementation. Configuration contract for an OpenAI-compatible API environment.
Type Aliases§
- Result
- Error type and result alias. Error type and result alias. Crate-level result type backed by a boxed dynamic error.