mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 04:50:52 +08:00
Add support for Codex API key authentication
- Introduced functionality to handle Codex API keys, including initialization and management via new endpoints in the management API. - Updated Codex client to support both OAuth and API key authentication. - Documented Codex API key configuration in both English and Chinese README files. - Enhanced logging to distinguish between API key and OAuth usage scenarios.
This commit is contained in:
@@ -44,6 +44,9 @@ type Config struct {
|
||||
// ClaudeKey defines a list of Claude API key configurations as specified in the YAML configuration file.
|
||||
ClaudeKey []ClaudeKey `yaml:"claude-api-key"`
|
||||
|
||||
// Codex defines a list of Codex API key configurations as specified in the YAML configuration file.
|
||||
CodexKey []CodexKey `yaml:"codex-api-key"`
|
||||
|
||||
// OpenAICompatibility defines OpenAI API compatibility configurations for external providers.
|
||||
OpenAICompatibility []OpenAICompatibility `yaml:"openai-compatibility"`
|
||||
|
||||
@@ -83,6 +86,17 @@ type ClaudeKey struct {
|
||||
BaseURL string `yaml:"base-url"`
|
||||
}
|
||||
|
||||
// CodexKey represents the configuration for a Codex API key,
|
||||
// including the API key itself and an optional base URL for the API endpoint.
|
||||
type CodexKey struct {
|
||||
// APIKey is the authentication key for accessing Codex API services.
|
||||
APIKey string `yaml:"api-key"`
|
||||
|
||||
// BaseURL is the base URL for the Codex API endpoint.
|
||||
// If empty, the default Codex API URL will be used.
|
||||
BaseURL string `yaml:"base-url"`
|
||||
}
|
||||
|
||||
// OpenAICompatibility represents the configuration for OpenAI API compatibility
|
||||
// with external providers, allowing model aliases to be routed through OpenAI API format.
|
||||
type OpenAICompatibility struct {
|
||||
@@ -286,58 +300,6 @@ func getOrCreateMapValue(mapNode *yaml.Node, key string) *yaml.Node {
|
||||
return val
|
||||
}
|
||||
|
||||
// Helpers to update sequences in place to preserve existing comments/anchors
|
||||
func setStringListInPlace(mapNode *yaml.Node, key string, arr []string) {
|
||||
if len(arr) == 0 {
|
||||
setNullValue(mapNode, key)
|
||||
return
|
||||
}
|
||||
v := getOrCreateMapValue(mapNode, key)
|
||||
if v.Kind != yaml.SequenceNode {
|
||||
v.Kind = yaml.SequenceNode
|
||||
v.Tag = "!!seq"
|
||||
v.Content = nil
|
||||
}
|
||||
// Update in place
|
||||
oldLen := len(v.Content)
|
||||
minLen := oldLen
|
||||
if len(arr) < minLen {
|
||||
minLen = len(arr)
|
||||
}
|
||||
for i := 0; i < minLen; i++ {
|
||||
if v.Content[i] == nil {
|
||||
v.Content[i] = &yaml.Node{Kind: yaml.ScalarNode, Tag: "!!str"}
|
||||
}
|
||||
v.Content[i].Kind = yaml.ScalarNode
|
||||
v.Content[i].Tag = "!!str"
|
||||
v.Content[i].Value = arr[i]
|
||||
}
|
||||
if len(arr) > oldLen {
|
||||
for i := oldLen; i < len(arr); i++ {
|
||||
v.Content = append(v.Content, &yaml.Node{Kind: yaml.ScalarNode, Tag: "!!str", Value: arr[i]})
|
||||
}
|
||||
} else if len(arr) < oldLen {
|
||||
v.Content = v.Content[:len(arr)]
|
||||
}
|
||||
}
|
||||
|
||||
func setMappingScalar(mapNode *yaml.Node, key string, val string) {
|
||||
v := getOrCreateMapValue(mapNode, key)
|
||||
v.Kind = yaml.ScalarNode
|
||||
v.Tag = "!!str"
|
||||
v.Value = val
|
||||
}
|
||||
|
||||
// setNullValue ensures a mapping key exists and is set to an explicit null scalar,
|
||||
// so that it renders as `key:` without `[]`.
|
||||
func setNullValue(mapNode *yaml.Node, key string) {
|
||||
// Represent as YAML null scalar without explicit value so it renders as `key:`
|
||||
v := getOrCreateMapValue(mapNode, key)
|
||||
v.Kind = yaml.ScalarNode
|
||||
v.Tag = "!!null"
|
||||
v.Value = ""
|
||||
}
|
||||
|
||||
// mergeMappingPreserve merges keys from src into dst mapping node while preserving
|
||||
// key order and comments of existing keys in dst. Unknown keys from src are appended
|
||||
// to dst at the end, copying their node structure from src.
|
||||
|
||||
Reference in New Issue
Block a user