Gh_models - Github models for Rust

โš“ Rust    ๐Ÿ“… 2025-10-04    ๐Ÿ‘ค surdeus    ๐Ÿ‘๏ธ 6      

surdeus

gh_models is a Rust crate providing a simple interface to the GitHub Models API. It enables calling GitHub-hosted AI models from Rust, similar to OpenAIโ€™s Python client.

Installation

Add to Cargo.toml:

gh_models = "0.1.0"

Authentication

Set a GitHub personal access token with model access as an environment variable:

export GITHUB_TOKEN=your_token_here

How to generate a token:
GitHub PAT documentation

Make sure when making a token you set the Models account permission:

Setting Models account permission

Usage Example

use gh_models::{GHModels, types::ChatMessage};
use std::env;

#[tokio::main]
async fn main() {
    let token = env::var("GITHUB_TOKEN").expect("GITHUB_TOKEN not set");
    let client = GHModels::new(token);

    let messages = vec![
        ChatMessage { role: "system".into(), content: "You are a helpful assistant.".into() },
        ChatMessage { role: "user".into(), content: "What is the capital of France?".into() },
    ];

    let response = client.chat_completion("openai/gpt-4o", messages, 1.0, 4096, 1.0).await.unwrap();
    println!("{}", response.choices[0].message.content);
}

Links

1 post - 1 participant

Read full topic

๐Ÿท๏ธ Rust_feed