openai

package
v0.0.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 19 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

llm proxy

Proxy LLM and remap model, and inspect request details.

Installation

go install github.com/xhd2015/llm-proxy@latest

Usages

Start a server:

llm-proxy --base-url https://api.anthropic.com --port 7788

Start cluade code with:

export ANTHROPIC_BASE_URL=http://localhost:7788
claude

Special note with sst/opencode

When running opencode with llm-proxy, you might encounter the following error:

Error: AI_TypeValidationError: Type validation failed: Value: {"type":"text","text":"I'm open","snapshot":"I'm open"}.
Error message: [{"code":"invalid_union","errors":[],"note":"No matching discriminator","discriminator":"type","path":["type"],"message":"Invalid input"}]

This is due to the server returned a message in the stream: {"type":"text","text":"I'm open","snapshot":"I'm open"}, which cannot be validated by the vercel AI SDK used by sst/opencode.

To tackle this issue:

llm-proxy --base-url https://api.anthropic.com --port 7789 --filter-text-snapshot

And configure opencode.json:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "anthropic": {
      "models": {
        "claude-sonnet-4-20250514": {
          "name": "Claude Sonnet 4"
        }
      },
      "options": {
        "apiKey": "<YOUR_API_KEY>",
        "baseURL": "http://localhost:7789"
      }
    }
  }
}

Test with opencode:

opencode run "Who are you?"

Result:

I'm opencode, an interactive CLI tool that helps with software engineering tasks. I can help you write code, debug issues, run commands, search through codebases, and manage development workflows.

Codex ChatGPT/OAuth proxy

Use --codex when Codex is signed in with ChatGPT/OAuth and you want to route Codex traffic through llm-proxy:

llm-proxy --codex --port 8891

Append full proxy logs while keeping terminal output brief:

llm-proxy --codex --port 8891 --log proxy.log

Configure Codex with the built-in OpenAI provider:

model_provider = "openai"
openai_base_url = "http://localhost:8891/v1"

Or with a custom provider:

model_provider = "llm-proxy"

[model_providers.llm-proxy]
name = "LLM Proxy"
base_url = "http://localhost:8891/v1"
requires_openai_auth = true
wire_api = "responses"
supports_websockets = true

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handle added in v0.0.6

func Handle(args []string) error

Handle dispatches a llm-proxy CLI invocation to the doc subcommand, the usage summary, the OpenAI/Codex proxies, or a generic --base-url proxy.

func HandleUsages

func HandleUsages(args []string) error

func PatchCodexSSEOutput added in v0.0.6

func PatchCodexSSEOutput(body []byte) []byte

PatchCodexSSEOutput delegates to the unexported patchCodexSSEOutput so the doctest harness can exercise SSE output-item injection.

func ReadCodexAuth added in v0.0.6

func ReadCodexAuth(path string) (accessToken string, accountID string, err error)

ReadCodexAuth delegates to the unexported readCodexAuth so the doctest harness can exercise auth.json parsing against temp files.

func StartAPIProxy

func StartAPIProxy(baseUrl string, modelMappings []string, port string, verbose bool, logFile string) error

func StartCodexProxy

func StartCodexProxy(baseUrl string, modelMappings []string, port string, verbose bool, logFile string) error

func TransformCodexRequest added in v0.0.6

func TransformCodexRequest(data map[string]interface{}, logf func(format string, args ...any))

TransformCodexRequest delegates to the unexported transformCodexRequest so the doctest harness can exercise system-message -> instructions adaptation.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL