Skip to main content

Crate api_openai_compatible

Crate api_openai_compatible 

Source
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 client
  • streaming — Server-Sent Events streaming support
  • sync_api — blocking wrappers around the async client
  • integration — real-API integration tests (requires live credentials)
  • full — enables enabled, streaming, and sync_api

§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 workspace spec.md 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 Client for synchronous contexts.

Structs§

ChatCompletionChunk
A single Server-Sent Events chunk from a streaming completion.
ChatCompletionRequest
Request body for the POST chat/completions endpoint.
ChatCompletionResponse
Response body from the POST chat/completions endpoint.
Choice
One completion alternative within a ChatCompletionResponse.
ChunkChoice
One delta choice within a streaming chunk.
Client
Async HTTP client for OpenAI-compatible REST APIs.
Delta
Partial message update delivered in a streaming chunk.
Function
Function specification (name, description, JSON Schema parameters).
FunctionCall
Name and arguments for a specific function invocation.
Message
A single message in a chat conversation.
OpenAiCompatEnvironmentImpl
Default OpenAI-compatible environment backed by in-memory values.
SyncClient
Blocking wrapper around Client for use in synchronous contexts.
Tool
A function tool definition passed in the tools array of a request.
ToolCall
A function invocation requested by the assistant.
Usage
Token usage statistics returned in every completion response.

Enums§

OpenAiCompatError
Error variants for OpenAI-compatible API operations.
Role
Role of a participant in a chat conversation.

Traits§

OpenAiCompatEnvironment
Configuration contract for an OpenAI-compatible API environment.

Type Aliases§

Result
Crate-level result type backed by a boxed dynamic error.