{"id":15288329,"url":"https://github.com/openai-rs/openai-api","last_synced_at":"2025-04-05T09:04:57.018Z","repository":{"id":150175665,"uuid":"617014949","full_name":"openai-rs/openai-api","owner":"openai-rs","description":"A simple Rust library for OpenAI API, free from complex async operations and redundant dependencies.","archived":false,"fork":false,"pushed_at":"2024-06-25T08:16:52.000Z","size":571,"stargazers_count":153,"open_issues_count":13,"forks_count":24,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-29T08:03:35.678Z","etag":null,"topics":["chatgpt","chatgpt-api","openai","openai-api","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/openai-rs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-21T14:33:27.000Z","updated_at":"2025-03-29T02:57:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"f3b4adb9-aad1-4274-9b31-875eef2c476b","html_url":"https://github.com/openai-rs/openai-api","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openai-rs%2Fopenai-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openai-rs%2Fopenai-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openai-rs%2Fopenai-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openai-rs%2Fopenai-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/openai-rs","download_url":"https://codeload.github.com/openai-rs/openai-api/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247312077,"owners_count":20918344,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chatgpt","chatgpt-api","openai","openai-api","rust"],"created_at":"2024-09-30T15:47:22.268Z","updated_at":"2025-04-05T09:04:56.975Z","avatar_url":"https://github.com/openai-rs.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OpenAI API for Rust\n\n[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/openai-rs/openai-api/rust.yml?style=flat-square)](https://github.com/openai-rs/openai-api/actions)\n[![Crates.io](https://img.shields.io/crates/v/openai_api_rust?style=flat-square)](https://crates.io/crates/openai_api_rust/versions)\n[![Crates.io](https://img.shields.io/crates/d/openai_api_rust?style=flat-square)](https://crates.io/crates/openai_api_rust)\n[![GitHub](https://img.shields.io/github/license/openai-rs/openai-api?style=flat-square)](https://github.com/openai-rs/openai-api/blob/main/LICENSE)\n\nA community-maintained library provides a simple and convenient way to interact with the OpenAI API.\nNo complex async and redundant dependencies.\n\n## API\n\ncheck [official API reference](https://platform.openai.com/docs/api-reference)\n|API|Support|\n|---|---|\n|Models|✔️|\n|Completions|✔️|\n|Chat|✔️|\n|Images|✔️|\n|Embeddings|✔️|\n|Audio|✔️|\n|Files|❌|\n|Fine-tunes|❌|\n|Moderations|❌|\n|Engines|❌|\n___\n\n## Usage\n\nAdd the following to your Cargo.toml file:\n\n```toml\nopenai_api_rust = \"0.1.9\"\n```\n\nExport your API key into the environment variables\n\n```bash\nexport OPENAI_API_KEY=\u003cyour_api_key\u003e\n```\n\nThen use the crate in your Rust code:\n\n```rust\nuse openai_api_rust::*;\nuse openai_api_rust::chat::*;\nuse openai_api_rust::completions::*;\n\nfn main() {\n    // Load API key from environment OPENAI_API_KEY.\n    // You can also hadcode through `Auth::new(\u003cyour_api_key\u003e)`, but it is not recommended.\n    let auth = Auth::from_env().unwrap();\n    let openai = OpenAI::new(auth, \"https://api.openai.com/v1/\");\n    let body = ChatBody {\n        model: \"gpt-3.5-turbo\".to_string(),\n        max_tokens: Some(7),\n        temperature: Some(0_f32),\n        top_p: Some(0_f32),\n        n: Some(2),\n        stream: Some(false),\n        stop: None,\n        presence_penalty: None,\n        frequency_penalty: None,\n        logit_bias: None,\n        user: None,\n        messages: vec![Message { role: Role::User, content: \"Hello!\".to_string() }],\n    };\n    let rs = openai.chat_completion_create(\u0026body);\n    let choice = rs.unwrap().choices;\n    let message = \u0026choice[0].message.as_ref().unwrap();\n    assert!(message.content.contains(\"Hello\"));\n}\n```\n\n### Use proxy\n\nLoad proxy from env\n\n```rust\nlet openai = OpenAI::new(auth, \"https://api.openai.com/v1/\")\n        .use_env_proxy();\n```\n\nSet the proxy manually\n\n```rust\nlet openai = OpenAI::new(auth, \"https://api.openai.com/v1/\")\n        .set_proxy(\"http://127.0.0.1:1080\");\n```\n\n## License\n\nThis library is distributed under the terms of the MIT license. See [LICENSE](LICENSE) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenai-rs%2Fopenai-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenai-rs%2Fopenai-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenai-rs%2Fopenai-api/lists"}