From 5845b5c6576aa7292bb1fa95d16f834b9e7a576a Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Fri, 18 Apr 2025 19:05:31 -0700 Subject: [PATCH] docs openai codex with litellm --- .../my-website/docs/tutorials/openai_codex.md | 107 +++++++++++++++--- 1 file changed, 89 insertions(+), 18 deletions(-) diff --git a/docs/my-website/docs/tutorials/openai_codex.md b/docs/my-website/docs/tutorials/openai_codex.md index a4fa5ecd60..08881d79ae 100644 --- a/docs/my-website/docs/tutorials/openai_codex.md +++ b/docs/my-website/docs/tutorials/openai_codex.md @@ -1,39 +1,70 @@ import Image from '@theme/IdealImage'; +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; # Using LiteLLM with OpenAI Codex -This tutorial walks you through setting up and using [OpenAI Codex](https://github.com/openai/codex) with LiteLLM Proxy. LiteLLM enables you to use various LLM models (including Gemini) through the Codex interface. +This guide walks you through connecting OpenAI Codex to LiteLLM. Using LiteLLM with Codex allows teams to: +- Access 100+ LLMs through the Codex interface +- Use powerful models like Gemini through a familiar interface +- Track spend and usage with LiteLLM's built-in analytics +- Control model access with virtual keys -## Prerequisites +## Quickstart -- LiteLLM Proxy running (see [Docker Quick Start Guide](../proxy/docker_quick_start.md) for setup details) -- Node.js and npm installed +Make sure to set up LiteLLM with the [LiteLLM Getting Started Guide](../proxy/docker_quick_start.md). -## Step 1: Install OpenAI Codex +## 1. Install OpenAI Codex Install the OpenAI Codex CLI tool globally using npm: + + + ```bash npm i -g @openai/codex ``` -## Step 2: Configure Codex to use LiteLLM Proxy - -Set the required environment variables to point Codex to your LiteLLM Proxy: + + ```bash -# Point to your LiteLLM Proxy server -export OPENAI_BASE_URL=http://0.0.0.0:4000 - -# Use your LiteLLM API key -export OPENAI_API_KEY="sk-1234" +yarn global add @openai/codex ``` -## Step 3: LiteLLM Configuration + + -Ensure your LiteLLM Proxy is properly configured to route to your desired models. Here's the example configuration: +## 2. Start LiteLLM Proxy + + + + +```bash +docker run \ + -v $(pwd)/litellm_config.yaml:/app/config.yaml \ + -p 4000:4000 \ + ghcr.io/berriai/litellm:main-latest \ + --config /app/config.yaml +``` + + + + +```bash +litellm --config /path/to/config.yaml +``` + + + + +LiteLLM should now be running on [http://localhost:4000](http://localhost:4000) + +## 3. Configure LiteLLM for Model Routing + +Ensure your LiteLLM Proxy is properly configured to route to your desired models. Create a `litellm_config.yaml` file with the following content: ```yaml model_list: @@ -52,7 +83,19 @@ litellm_settings: This configuration enables routing to OpenAI, Anthropic, and Gemini models. -## Step 4: Run Codex with Gemini +## 4. Configure Codex to Use LiteLLM Proxy + +Set the required environment variables to point Codex to your LiteLLM Proxy: + +```bash +# Point to your LiteLLM Proxy server +export OPENAI_BASE_URL=http://0.0.0.0:4000 + +# Use your LiteLLM API key (if you've set up authentication) +export OPENAI_API_KEY="sk-1234" +``` + +## 5. Run Codex with Gemini With everything configured, you can now run Codex with Gemini: @@ -60,14 +103,42 @@ With everything configured, you can now run Codex with Gemini: codex --model gemini/gemini-2.0-flash --full-auto ``` + + The `--full-auto` flag allows Codex to automatically generate code without additional prompting. +## 6. Advanced Options + +### Using Different Models + +You can use any model configured in your LiteLLM proxy: + +```bash +# Use Claude models +codex --model anthropic/claude-3-opus-20240229 + +# Use OpenAI models +codex --model openai/gpt-4o +``` + +### Enabling Debugging + +For troubleshooting, enable verbose output: + +```bash +export DEBUG=1 +codex --model gemini/gemini-2.0-flash --full-auto +``` + ## Troubleshooting - If you encounter connection issues, ensure your LiteLLM Proxy is running and accessible at the specified URL -- Verify your LiteLLM API key is valid +- Verify your LiteLLM API key is valid if you're using authentication - Check that your model routing configuration is correct +- For model-specific errors, ensure the model is properly configured in your LiteLLM setup ## Additional Resources -For more details on starting and configuring LiteLLM, refer to the [Docker Quick Start Guide](../proxy/docker_quick_start.md). +- [LiteLLM Docker Quick Start Guide](../proxy/docker_quick_start.md) +- [OpenAI Codex GitHub Repository](https://github.com/openai/codex) +- [LiteLLM Virtual Keys and Authentication](../proxy/virtual_keys.md)