diff --git a/crates/goose/src/providers/openai.rs b/crates/goose/src/providers/openai.rs index c575b382e3..ac0e256651 100644 --- a/crates/goose/src/providers/openai.rs +++ b/crates/goose/src/providers/openai.rs @@ -29,6 +29,8 @@ pub struct OpenAiProvider { client: Client, host: String, api_key: String, + organization: Option, + project: Option, model: ModelConfig, } @@ -46,6 +48,8 @@ impl OpenAiProvider { let host: String = config .get("OPENAI_HOST") .unwrap_or_else(|_| "https://api.openai.com".to_string()); + let organization: Option = config.get("OPENAI_ORGANIZATION").ok(); + let project: Option = config.get("OPENAI_PROJECT").ok(); let client = Client::builder() .timeout(Duration::from_secs(600)) .build()?; @@ -54,6 +58,8 @@ impl OpenAiProvider { client, host, api_key, + organization, + project, model, }) } @@ -65,13 +71,22 @@ impl OpenAiProvider { ProviderError::RequestFailed(format!("Failed to construct endpoint URL: {e}")) })?; - let response = self + let mut request = self .client .post(url) - .header("Authorization", format!("Bearer {}", self.api_key)) - .json(&payload) - .send() - .await?; + .header("Authorization", format!("Bearer {}", self.api_key)); + + // Add organization header if present + if let Some(org) = &self.organization { + request = request.header("OpenAI-Organization", org); + } + + // Add project header if present + if let Some(project) = &self.project { + request = request.header("OpenAI-Project", project); + } + + let response = request.json(&payload).send().await?; handle_response_openai_compat(response).await } @@ -93,6 +108,8 @@ impl Provider for OpenAiProvider { vec![ ConfigKey::new("OPENAI_API_KEY", true, true, None), ConfigKey::new("OPENAI_HOST", false, false, Some("https://api.openai.com")), + ConfigKey::new("OPENAI_ORGANIZATION", false, false, None), + ConfigKey::new("OPENAI_PROJECT", false, false, None), ], ) } diff --git a/documentation/docs/getting-started/providers.md b/documentation/docs/getting-started/providers.md index 0f57e01339..0384dc59d0 100644 --- a/documentation/docs/getting-started/providers.md +++ b/documentation/docs/getting-started/providers.md @@ -26,7 +26,7 @@ Goose relies heavily on tool calling capabilities and currently works best with | [Gemini](https://ai.google.dev/gemini-api/docs) | Advanced LLMs by Google with multimodal capabilities (text, images). | `GOOGLE_API_KEY` | | [Groq](https://groq.com/) | High-performance inference hardware and tools for LLMs. | `GROQ_API_KEY` | | [Ollama](https://ollama.com/) | Local model runner supporting Qwen, Llama, DeepSeek, and other open-source models. **Because this provider runs locally, you must first [download and run a model](/docs/getting-started/providers#local-llms-ollama).** | `OLLAMA_HOST` | -| [OpenAI](https://platform.openai.com/api-keys) | Provides gpt-4o, o1, and other advanced language models. **o1-mini and o1-preview are not supported because Goose uses tool calling.** | `OPENAI_API_KEY` | +| [OpenAI](https://platform.openai.com/api-keys) | Provides gpt-4o, o1, and other advanced language models. Also supports OpenAI-compatible endpoints (e.g., self-hosted LLaMA, vLLM, KServe). **o1-mini and o1-preview are not supported because Goose uses tool calling.** | `OPENAI_API_KEY`, `OPENAI_HOST` (optional), `OPENAI_ORGANIZATION` (optional), `OPENAI_PROJECT` (optional) | | [OpenRouter](https://openrouter.ai/) | API gateway for unified access to various models with features like rate-limiting management. | `OPENROUTER_API_KEY` | @@ -105,11 +105,89 @@ To configure your chosen provider or see available options, run `goose configure 5. Select a Provider from drop down menu 6. Enter Model name and press `+ Add Model` - You can explore more models by selecting a `provider` name under `Browse by Provider`. A link will appear, directing you to the provider’s website. Once you've found the model you want, return to step 6 and paste the model name. + You can explore more models by selecting a `provider` name under `Browse by Provider`. A link will appear, directing you to the provider's website. Once you've found the model you want, return to step 6 and paste the model name. +## Using Custom OpenAI Endpoints + +Goose supports using custom OpenAI-compatible endpoints, which is particularly useful for: +- Self-hosted LLMs (e.g., LLaMA, Mistral) using vLLM or KServe +- Private OpenAI-compatible API servers +- Enterprise deployments requiring data governance and security compliance +- OpenAI API proxies or gateways + +### Configuration Parameters + +| Parameter | Required | Description | +|-----------|----------|-------------| +| `OPENAI_API_KEY` | Yes | Authentication key for the API | +| `OPENAI_HOST` | No | Custom endpoint URL (defaults to api.openai.com) | +| `OPENAI_ORGANIZATION` | No | Organization ID for usage tracking and governance | +| `OPENAI_PROJECT` | No | Project identifier for resource management | + +### Example Configurations + + + + If you're running LLaMA or other models using vLLM with OpenAI compatibility: + ```sh + OPENAI_HOST=https://your-vllm-endpoint.internal + OPENAI_API_KEY=your-internal-api-key + ``` + + + For models deployed on Kubernetes using KServe: + ```sh + OPENAI_HOST=https://kserve-gateway.your-cluster + OPENAI_API_KEY=your-kserve-api-key + OPENAI_ORGANIZATION=your-org-id + OPENAI_PROJECT=ml-serving + ``` + + + For enterprise OpenAI deployments with governance: + ```sh + OPENAI_API_KEY=your-api-key + OPENAI_ORGANIZATION=org-id123 + OPENAI_PROJECT=compliance-approved + ``` + + + +### Setup Instructions + + + + 1. Run `goose configure` + 2. Select `Configure Providers` + 3. Choose `OpenAI` as the provider + 4. Enter your configuration when prompted: + - API key + - Host URL (if using custom endpoint) + - Organization ID (if using organization tracking) + - Project identifier (if using project management) + + + 1. Click `...` in the upper right corner + 2. Click `Settings` + 3. Next to `Models`, click the `browse` link + 4. Click the `configure` link in the upper right corner + 5. Press the `+` button next to OpenAI + 6. Fill in your configuration details: + - API Key (required) + - Host URL (for custom endpoints) + - Organization ID (for usage tracking) + - Project (for resource management) + 7. Press `submit` + + + +:::tip Enterprise Deployment +For enterprise deployments, you can pre-configure these values using environment variables or configuration files to ensure consistent governance across your organization. +::: + ## Using Goose for Free Goose is a free and open source AI agent that you can start using right away, but not all supported [LLM Providers][providers] provide a free tier.