<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://tech.uvoo.io/index.php?action=history&amp;feed=atom&amp;title=Codex_use_local_openai_api</id>
	<title>Codex use local openai api - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://tech.uvoo.io/index.php?action=history&amp;feed=atom&amp;title=Codex_use_local_openai_api"/>
	<link rel="alternate" type="text/html" href="https://tech.uvoo.io/index.php?title=Codex_use_local_openai_api&amp;action=history"/>
	<updated>2026-05-30T20:08:14Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.2</generator>
	<entry>
		<id>https://tech.uvoo.io/index.php?title=Codex_use_local_openai_api&amp;diff=5694&amp;oldid=prev</id>
		<title>Busk: Created page with &quot;To point the **Codex CLI** to your local `llama-server`, you primarily need to override the environment variables that the tool uses to locate the OpenAI API.  Since the Codex...&quot;</title>
		<link rel="alternate" type="text/html" href="https://tech.uvoo.io/index.php?title=Codex_use_local_openai_api&amp;diff=5694&amp;oldid=prev"/>
		<updated>2026-05-22T15:57:28Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;To point the **Codex CLI** to your local `llama-server`, you primarily need to override the environment variables that the tool uses to locate the OpenAI API.  Since the Codex...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;To point the **Codex CLI** to your local `llama-server`, you primarily need to override the environment variables that the tool uses to locate the OpenAI API.&lt;br /&gt;
&lt;br /&gt;
Since the Codex CLI (and most OpenAI-compatible tools) follows standard OpenAI SDK conventions, you can redirect its traffic by pointing `OPENAI_BASE_URL` to your local endpoint.&lt;br /&gt;
&lt;br /&gt;
### 1. Set the Environment Variables&lt;br /&gt;
&lt;br /&gt;
You need to set these in your shell configuration (e.g., `~/.zshrc`, `~/.bashrc`) or for the specific session where you run the command.&lt;br /&gt;
&lt;br /&gt;
* **`OPENAI_BASE_URL`**: Set this to your `llama-server` address, ensuring you include the `/v1` path.&lt;br /&gt;
* **`OPENAI_API_KEY`**: Even if your `llama-server` doesn't require authentication, the CLI usually expects this variable to exist. You can set it to any dummy string (e.g., `sk-no-key`).&lt;br /&gt;
&lt;br /&gt;
**Example for your shell configuration:**&lt;br /&gt;
&lt;br /&gt;
```bash&lt;br /&gt;
export OPENAI_BASE_URL=&amp;quot;http://localhost:8080/v1&amp;quot;&lt;br /&gt;
export OPENAI_API_KEY=&amp;quot;sk-not-needed&amp;quot;&lt;br /&gt;
&lt;br /&gt;
```&lt;br /&gt;
&lt;br /&gt;
*After saving this, run `source ~/.zshrc` (or your relevant shell config file) to apply the changes.*&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
### 2. Configure via `config.toml` (Optional/Permanent)&lt;br /&gt;
&lt;br /&gt;
If you prefer a more permanent configuration—or if you need to use a specific model name that `llama-server` might not report by default—you can define a provider profile in the Codex CLI configuration file, typically located at `~/.codex/config.toml`.&lt;br /&gt;
&lt;br /&gt;
Add a custom provider section like this:&lt;br /&gt;
&lt;br /&gt;
```toml&lt;br /&gt;
# In ~/.codex/config.toml&lt;br /&gt;
&lt;br /&gt;
[model_providers.local]&lt;br /&gt;
name = &amp;quot;Llama Server&amp;quot;&lt;br /&gt;
base_url = &amp;quot;http://localhost:8080/v1&amp;quot;&lt;br /&gt;
env_key = &amp;quot;OPENAI_API_KEY&amp;quot;&lt;br /&gt;
&lt;br /&gt;
```&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
### 3. Verify the Connection&lt;br /&gt;
&lt;br /&gt;
Once the environment variables are set, test the connection by running a simple command:&lt;br /&gt;
&lt;br /&gt;
```bash&lt;br /&gt;
codex &amp;quot;What is the capital of Utah?&amp;quot;&lt;br /&gt;
&lt;br /&gt;
```&lt;br /&gt;
&lt;br /&gt;
### Important Tips for Local Models&lt;br /&gt;
&lt;br /&gt;
* **Model Name:** If the CLI complains that the &amp;quot;model is not found,&amp;quot; you may need to explicitly specify the model name that `llama-server` is reporting. You can check what models are available by hitting the `/v1/models` endpoint directly:&lt;br /&gt;
`curl http://localhost:8080/v1/models`&lt;br /&gt;
* **Compatibility:** Some &amp;quot;agentic&amp;quot; features of high-end CLI tools rely on OpenAI-specific function calling or vision capabilities. Depending on the model you are running in `llama.cpp` (e.g., a standard Llama 3 vs. a specialized coding model), some advanced agentic behaviors might have varying success compared to using a proprietary model like `gpt-4o`.&lt;br /&gt;
* **SSL/HTTPS:** Ensure your `llama-server` is running on `http` (or that you handle any certificate issues if you've enabled HTTPS), as CLI tools often fail with self-signed local certificates.&lt;/div&gt;</summary>
		<author><name>Busk</name></author>
	</entry>
</feed>