Skip to content
Try chatGet API key

Rig

Rig is a Rust library for building LLM applications and agents. Its OpenAI client takes a custom base URL.

Copies this page's setup instructions, to paste into your coding agent.
Show the prompt
Help me set this up to use Bayle AI, an OpenAI-compatible API. Full guide: https://docs.bayle.ai/guides/sdks/rig/

Goal: build a Rust LLM agent with Rig (https://rig.rs) on a Bayle model.

1. Add the crates to my Cargo project if they are missing:
   cargo add rig anyhow
   cargo add tokio --features macros,rt-multi-thread
2. Pick a model:
   curl -s "https://api.bayle.ai/models?type=text" | jq -r '.data[].id'
   Show me the list, let me choose, and use that id as MODEL_ID.
3. Write the client like this, building the config yourself: `OpenAI::from_env()` reads OPENAI_API_KEY and OPENAI_BASE_URL, not BAYLE_API_KEY. Use `client.chat(...)`, which calls chat completions; the client's `completion(...)` defaults to OpenAI's Responses API, which Bayle does not serve:
   use rig::prelude::*;
   use rig::providers::openai::OpenAIConfig;

   #[tokio::main]
   async fn main() -> Result<(), anyhow::Error> {
       let key = std::env::var("BAYLE_API_KEY")?;
       let client = OpenAIConfig::new(key)
           .with_base_url("https://api.bayle.ai")
           .client();

       let agent = AgentBuilder::new(client.chat("MODEL_ID"))
           .preamble("You are a concise assistant.")
           .build();

       let response = agent.prompt("In one sentence, what is an embedding?").await?;
       println!("{}", response.output());
       Ok(())
   }
   If I already have a Rig project, change only how the client is built.
4. Verify with `cargo run` and show me the output.

Rules:
1. The base URL is https://api.bayle.ai exactly as written. Append no path to it.
2. Read the key from the BAYLE_API_KEY environment variable. Never write the key itself into a file you create, a command, a commit or the chat. Where the tool keeps the key in its own settings screen, tell me where to paste it. If BAYLE_API_KEY is not set, stop and ask me to create a key at https://chat.bayle.ai/developers and export it.
3. Take model ids only from GET https://api.bayle.ai/models (no key needed). Never guess one.
4. Finish with one real test request, show me the result and list the files you changed.
Terminal window
cargo add rig anyhow
cargo add tokio --features macros,rt-multi-thread

See the official docs for the other providers and features.

Don't have a Bayle key yet?Get API key
use rig::prelude::*;
use rig::providers::openai::OpenAIConfig;
#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
let key = std::env::var("BAYLE_API_KEY")?;
let client = OpenAIConfig::new(key)
.with_base_url("https://api.bayle.ai")
.client();
let agent = AgentBuilder::new(client.chat("MODEL_ID"))
.preamble("You are a concise assistant.")
.build();
let response = agent.prompt("In one sentence, what is an embedding?").await?;
println!("{}", response.output());
Ok(())
}
  • Use client.chat(...), which calls chat completions. The client’s completion(...) defaults to OpenAI’s Responses API, which Bayle doesn’t serve.
  • Build the config yourself, as above. OpenAI::from_env() reads OPENAI_API_KEY and OPENAI_BASE_URL, not BAYLE_API_KEY.
Terminal window
curl -s "https://api.bayle.ai/models?type=text" | jq -r '.data[].id'