openai

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 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

When routing the Codex backend to Grok CLI, add --feed-to-grok-cli to enable Grok CLI compatibility behavior: incompatible JSON keepalive SSE events are dropped while logged, and the local proxy serves Grok's models-v2 catalog request from the Codex model cache.

llm-proxy --codex --feed-to-grok-cli --port 8891

See Grok CLI compatibility for the session-resume behavior, model catalog response, and opt-in scope.

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 ApplyModelCapabilities added in v0.0.10

func ApplyModelCapabilities(data map[string]interface{}, caps map[string]ModelCapability, logf func(format string, args ...any)) int

ApplyModelCapabilities delegates to the unexported applyModelCapabilities so the doctest harness can exercise image stripping on decoded request bodies.

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 ParseModelCapabilities added in v0.0.10

func ParseModelCapabilities(entries []string) (map[string]ModelCapability, error)

ParseModelCapabilities delegates to the unexported parseModelCapabilities so the doctest harness can exercise --model-capability flag parsing.

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, modelCaps map[string]ModelCapability) error

func StartCodexProxy

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

StartCodexProxy starts a Codex OAuth proxy with the default stream behavior.

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

type ModelCapability added in v0.0.10

type ModelCapability uint

ModelCapability is a bitmask of per-model capability limits declared via --model-capability MODEL=opt1,opt2.

const (
	// CapNoImage marks a model that rejects image input upstream (e.g. a
	// text-only gateway endpoint answers 404). Image content parts are
	// replaced with a text note before the request leaves the proxy.
	CapNoImage ModelCapability = 1 << iota
)

Jump to

Keyboard shortcuts

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