xai-openapi
Rust types for the xAI API, including support for Grok models.
All types are generated from the OpenAPI specification included in this repository.
Installation
Add this to your Cargo.toml:
[]
= "0.1"
Or use cargo:
Usage
This crate provides type definitions only. You'll need to bring your own HTTP client (e.g., reqwest, ureq).
use ;
// Create a chat completion request
let request = ChatRequest ;
// Serialize to JSON for your HTTP client
let json = to_string.unwrap;
Tool Calling
use ;
use json;
let request = ChatRequest ;
Embeddings
use ;
let request = EmbeddingRequest ;
Image Generation
use GenerateImageRequest;
let request = GenerateImageRequest ;
Features
std (default)
Enables standard library support. Uses std::collections::HashMap.
no_std Support
This crate supports no_std environments. Disable default features and the crate will use hashbrown::HashMap instead:
[]
= { = "0.1", = false }
API Coverage
| Module | Endpoint | Description |
|---|---|---|
chat |
/v1/chat/completions |
Chat completions with streaming support |
responses |
/v1/responses |
Responses API (OpenAI-compatible) |
embeddings |
/v1/embeddings |
Text embeddings |
images |
/v1/images/generations |
Image generation and editing |
models |
/v1/models |
Model information and listing |
messages |
/v1/messages |
Anthropic-compatible messages API |
search |
/v1/documents/search |
Document search and retrieval |
tokenize |
/v1/tokenize-text |
Text tokenization |
tools |
- | Tool/function calling types |
usage |
- | Token usage tracking |
common |
- | Shared types (Content, ImageUrl, etc.) |
Type Conventions
All types follow these conventions:
- Derive
Clone,Debug,Default,PartialEq,Serialize,Deserialize - Optional fields use
Option<T>with#[serde(skip_serializing_if = "Option::is_none")] - Enums use appropriate serde attributes (
#[serde(tag = "type")],#[serde(untagged)], etc.)
Re-exports
Common types are re-exported at the crate root for convenience:
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use Usage;
Minimum Supported Rust Version (MSRV)
This crate requires Rust 1.75 or later.
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.