openai-http-proxy 3.2.3__tar.gz → 3.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. {openai_http_proxy-3.2.3 → openai_http_proxy-3.3.0}/PKG-INFO +33 -4
  2. {openai_http_proxy-3.2.3 → openai_http_proxy-3.3.0}/README.md +31 -2
  3. {openai_http_proxy-3.2.3 → openai_http_proxy-3.3.0}/lm_proxy/bootstrap.py +4 -1
  4. {openai_http_proxy-3.2.3 → openai_http_proxy-3.3.0}/lm_proxy/config.py +4 -0
  5. openai_http_proxy-3.3.0/lm_proxy/config_loaders/json.py +11 -0
  6. openai_http_proxy-3.3.0/lm_proxy/config_loaders/toml.py +11 -0
  7. {openai_http_proxy-3.2.3 → openai_http_proxy-3.3.0}/lm_proxy/core.py +29 -0
  8. {openai_http_proxy-3.2.3 → openai_http_proxy-3.3.0}/pyproject.toml +2 -2
  9. openai_http_proxy-3.2.3/lm_proxy/config_loaders/json.py +0 -9
  10. openai_http_proxy-3.2.3/lm_proxy/config_loaders/toml.py +0 -9
  11. {openai_http_proxy-3.2.3 → openai_http_proxy-3.3.0}/LICENSE +0 -0
  12. {openai_http_proxy-3.2.3 → openai_http_proxy-3.3.0}/lm_proxy/__init__.py +0 -0
  13. {openai_http_proxy-3.2.3 → openai_http_proxy-3.3.0}/lm_proxy/__main__.py +0 -0
  14. {openai_http_proxy-3.2.3 → openai_http_proxy-3.3.0}/lm_proxy/api_key_check/__init__.py +0 -0
  15. {openai_http_proxy-3.2.3 → openai_http_proxy-3.3.0}/lm_proxy/api_key_check/allow_all.py +0 -0
  16. {openai_http_proxy-3.2.3 → openai_http_proxy-3.3.0}/lm_proxy/api_key_check/in_config.py +0 -0
  17. {openai_http_proxy-3.2.3 → openai_http_proxy-3.3.0}/lm_proxy/api_key_check/with_request.py +0 -0
  18. {openai_http_proxy-3.2.3 → openai_http_proxy-3.3.0}/lm_proxy/app.py +0 -0
  19. {openai_http_proxy-3.2.3 → openai_http_proxy-3.3.0}/lm_proxy/base_types.py +0 -0
  20. {openai_http_proxy-3.2.3 → openai_http_proxy-3.3.0}/lm_proxy/config_loaders/__init__.py +0 -0
  21. {openai_http_proxy-3.2.3 → openai_http_proxy-3.3.0}/lm_proxy/config_loaders/python.py +0 -0
  22. {openai_http_proxy-3.2.3 → openai_http_proxy-3.3.0}/lm_proxy/config_loaders/yaml.py +0 -0
  23. {openai_http_proxy-3.2.3 → openai_http_proxy-3.3.0}/lm_proxy/errors.py +0 -0
  24. {openai_http_proxy-3.2.3 → openai_http_proxy-3.3.0}/lm_proxy/handlers/__init__.py +0 -0
  25. {openai_http_proxy-3.2.3 → openai_http_proxy-3.3.0}/lm_proxy/handlers/forward_http_headers.py +0 -0
  26. {openai_http_proxy-3.2.3 → openai_http_proxy-3.3.0}/lm_proxy/handlers/rate_limiter.py +0 -0
  27. {openai_http_proxy-3.2.3 → openai_http_proxy-3.3.0}/lm_proxy/loggers.py +0 -0
  28. {openai_http_proxy-3.2.3 → openai_http_proxy-3.3.0}/lm_proxy/models_endpoint.py +0 -0
  29. {openai_http_proxy-3.2.3 → openai_http_proxy-3.3.0}/lm_proxy/strategies/__init__.py +0 -0
  30. {openai_http_proxy-3.2.3 → openai_http_proxy-3.3.0}/lm_proxy/strategies/fallback.py +0 -0
  31. {openai_http_proxy-3.2.3 → openai_http_proxy-3.3.0}/lm_proxy/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: openai-http-proxy
3
- Version: 3.2.3
3
+ Version: 3.3.0
4
4
  Summary: OpenAI HTTP Proxy is an OpenAI-compatible http proxy server for inferencing various LLMs capable of working with Google, Anthropic, OpenAI APIs, local PyTorch inference, etc.
5
5
  License: MIT License
6
6
 
@@ -46,7 +46,7 @@ Provides-Extra: all
46
46
  Provides-Extra: anthropic
47
47
  Provides-Extra: google
48
48
  Provides-Extra: test
49
- Requires-Dist: ai-microcore (>=6.2.1,<7)
49
+ Requires-Dist: ai-microcore (>=6.6.1,<7)
50
50
  Requires-Dist: anthropic (>=0.77,<1) ; extra == "all"
51
51
  Requires-Dist: anthropic (>=0.77,<1) ; extra == "anthropic"
52
52
  Requires-Dist: fastapi (>=0.136.3,<1)
@@ -116,6 +116,8 @@ It works as a drop-in replacement for OpenAI's API, allowing you to switch betwe
116
116
  - [Guides & Reference](#-guides--reference)
117
117
  - [Known Limitations](#-known-limitations)
118
118
  - [Debugging](#-debugging)
119
+ - [Debugging Mode](#debugging-mode)
120
+ - [Printing LLM Requests and Responses](#printing-llm-requests-and-responses)
119
121
  - [Contributing](#-contributing)
120
122
  - [License](#-license)
121
123
 
@@ -255,6 +257,7 @@ OpenAI HTTP Proxy is configured through a TOML/YAML/JSON/Python file that specif
255
257
  host = "0.0.0.0" # Interface to bind to
256
258
  port = 8000 # Port to listen on
257
259
  dev_autoreload = false # Enable for development
260
+ print_stream = false # Print LLM requests / responses to stdout, see "Debugging"
258
261
 
259
262
  # API key validation function (optional)
260
263
  api_key_check = "lm_proxy.api_key_check.check_api_key_in_config"
@@ -761,7 +764,9 @@ For more detailed information, check out these articles:
761
764
 
762
765
  ## 🔍 Debugging<a id="-debugging"></a>
763
766
 
764
- ### Overview
767
+ ### Debugging Mode<a id="debugging-mode"></a>
768
+
769
+ #### Overview
765
770
  When **debugging mode** is enabled,
766
771
  OpenAI HTTP Proxy provides detailed logging information to help diagnose issues:
767
772
  - Stack traces for exceptions are shown in the console
@@ -770,7 +775,7 @@ OpenAI HTTP Proxy provides detailed logging information to help diagnose issues:
770
775
  > **Warning** ⚠️
771
776
  > Never enable debugging mode in production environments, as it may expose sensitive information to the application logs.
772
777
 
773
- ### Enabling Debugging Mode
778
+ #### Enabling Debugging Mode
774
779
  To enable debugging, set the `LM_PROXY_DEBUG` environment variable to a truthy value (e.g., "1", "true", "yes").
775
780
  > **Tip** 💡
776
781
  > Environment variables can also be defined in a `.env` file.
@@ -782,6 +787,30 @@ Alternatively, you can enable or disable debugging via the command-line argument
782
787
  > **Note** ℹ️
783
788
  > CLI arguments override environment variable settings.
784
789
 
790
+ ### Printing LLM Requests and Responses<a id="printing-llm-requests-and-responses"></a>
791
+
792
+ The `print_stream` configuration option makes OpenAI HTTP Proxy print every LLM request
793
+ and response to stdout, with the response appearing token by token as it is generated:
794
+
795
+ ```toml
796
+ print_stream = true
797
+ ```
798
+
799
+ ```text
800
+ Requesting LLM gpt-5:
801
+ [User]:
802
+ What is the capital of France?
803
+ LLM Response:
804
+ The capital of France is Paris.
805
+ ```
806
+
807
+ This works for both streaming and non-streaming client requests.
808
+
809
+ > **Warning** ⚠️
810
+ > Intended for local development and troubleshooting only.
811
+ > Prompts and generated content are written to the console in plain text,
812
+ > and the output of requests processed in parallel is interleaved.
813
+
785
814
 
786
815
  ## 🤝 Contributing<a id="-contributing"></a>
787
816
 
@@ -50,6 +50,8 @@ It works as a drop-in replacement for OpenAI's API, allowing you to switch betwe
50
50
  - [Guides & Reference](#-guides--reference)
51
51
  - [Known Limitations](#-known-limitations)
52
52
  - [Debugging](#-debugging)
53
+ - [Debugging Mode](#debugging-mode)
54
+ - [Printing LLM Requests and Responses](#printing-llm-requests-and-responses)
53
55
  - [Contributing](#-contributing)
54
56
  - [License](#-license)
55
57
 
@@ -189,6 +191,7 @@ OpenAI HTTP Proxy is configured through a TOML/YAML/JSON/Python file that specif
189
191
  host = "0.0.0.0" # Interface to bind to
190
192
  port = 8000 # Port to listen on
191
193
  dev_autoreload = false # Enable for development
194
+ print_stream = false # Print LLM requests / responses to stdout, see "Debugging"
192
195
 
193
196
  # API key validation function (optional)
194
197
  api_key_check = "lm_proxy.api_key_check.check_api_key_in_config"
@@ -695,7 +698,9 @@ For more detailed information, check out these articles:
695
698
 
696
699
  ## 🔍 Debugging<a id="-debugging"></a>
697
700
 
698
- ### Overview
701
+ ### Debugging Mode<a id="debugging-mode"></a>
702
+
703
+ #### Overview
699
704
  When **debugging mode** is enabled,
700
705
  OpenAI HTTP Proxy provides detailed logging information to help diagnose issues:
701
706
  - Stack traces for exceptions are shown in the console
@@ -704,7 +709,7 @@ OpenAI HTTP Proxy provides detailed logging information to help diagnose issues:
704
709
  > **Warning** ⚠️
705
710
  > Never enable debugging mode in production environments, as it may expose sensitive information to the application logs.
706
711
 
707
- ### Enabling Debugging Mode
712
+ #### Enabling Debugging Mode
708
713
  To enable debugging, set the `LM_PROXY_DEBUG` environment variable to a truthy value (e.g., "1", "true", "yes").
709
714
  > **Tip** 💡
710
715
  > Environment variables can also be defined in a `.env` file.
@@ -716,6 +721,30 @@ Alternatively, you can enable or disable debugging via the command-line argument
716
721
  > **Note** ℹ️
717
722
  > CLI arguments override environment variable settings.
718
723
 
724
+ ### Printing LLM Requests and Responses<a id="printing-llm-requests-and-responses"></a>
725
+
726
+ The `print_stream` configuration option makes OpenAI HTTP Proxy print every LLM request
727
+ and response to stdout, with the response appearing token by token as it is generated:
728
+
729
+ ```toml
730
+ print_stream = true
731
+ ```
732
+
733
+ ```text
734
+ Requesting LLM gpt-5:
735
+ [User]:
736
+ What is the capital of France?
737
+ LLM Response:
738
+ The capital of France is Paris.
739
+ ```
740
+
741
+ This works for both streaming and non-streaming client requests.
742
+
743
+ > **Warning** ⚠️
744
+ > Intended for local development and troubleshooting only.
745
+ > Prompts and generated content are written to the console in plain text,
746
+ > and the output of requests processed in parallel is interleaved.
747
+
719
748
 
720
749
  ## 🤝 Contributing<a id="-contributing"></a>
721
750
 
@@ -94,7 +94,10 @@ class Env:
94
94
  env.connections[conn_name] = mc.env().llm_async_function
95
95
  except mc.LLMConfigError as e:
96
96
  raise ValueError(f"Error in configuration for connection '{conn_name}': {e}") from e
97
-
97
+ if config.print_stream:
98
+ mc.use_logging(stream=True)
99
+ # Proxied prompts are printed in full, without "...(output was truncated)..."
100
+ mc.logging.LoggingConfig.STRIP_REQUEST_LINES = None
98
101
  logging.info("Done initializing %d connections.", len(env.connections))
99
102
 
100
103
 
@@ -90,6 +90,10 @@ class Config(BaseModel):
90
90
  )
91
91
  components: dict[str, Union[str, Callable, dict]] = Field(default_factory=dict)
92
92
  before: list[Union[str, Callable, dict]] = Field(default_factory=list)
93
+ print_stream: bool = Field(
94
+ default=False,
95
+ description="Prints LLM requests / responses to stdout"
96
+ )
93
97
 
94
98
  def __init__(self, **data):
95
99
  super().__init__(**data)
@@ -0,0 +1,11 @@
1
+ """JSON configuration loader."""
2
+
3
+ import json
4
+
5
+
6
+ def load_json_config(config_path: str) -> dict:
7
+ """Loads configuration from a JSON file."""
8
+ # utf-8-sig skips the byte order mark that Windows text editors may add,
9
+ # the JSON parser rejects it
10
+ with open(config_path, "r", encoding="utf-8-sig") as f:
11
+ return json.load(f)
@@ -0,0 +1,11 @@
1
+ """TOML configuration loader."""
2
+
3
+ import tomllib
4
+
5
+
6
+ def load_toml_config(config_path: str) -> dict:
7
+ """Loads configuration from a TOML file."""
8
+ # utf-8-sig skips the byte order mark that Windows text editors may add,
9
+ # tomllib rejects it
10
+ with open(config_path, "r", encoding="utf-8-sig") as f:
11
+ return tomllib.loads(f.read())
@@ -11,6 +11,7 @@ import inspect
11
11
  from datetime import datetime
12
12
  from typing import Optional
13
13
 
14
+ import microcore as mc
14
15
  from fastapi import HTTPException
15
16
  from openai.types.chat.chat_completion import Choice
16
17
  from starlette.requests import Request
@@ -65,6 +66,30 @@ def resolve_connection_and_model(config: Config, external_model: str) -> tuple[s
65
66
  )
66
67
 
67
68
 
69
+ def print_llm_request(ctx: RequestContext):
70
+ """
71
+ Prints the LLM request to stdout when the `print_stream` option is enabled.
72
+
73
+ LM-Proxy queries the LLM API function directly instead of using microcore.allm(),
74
+ so microcore request / response handlers are triggered explicitly.
75
+ """
76
+ if env.config.print_stream:
77
+ for handler in mc.env().llm_before_handlers:
78
+ handler(ctx.request.messages, **ctx.llm_params)
79
+
80
+
81
+ def finish_printing_llm_response(ctx: RequestContext):
82
+ """
83
+ Completes printing of the LLM response to stdout, in particular terminates
84
+ the line of the streamed output, when the `print_stream` option is enabled.
85
+
86
+ See print_llm_request().
87
+ """
88
+ if env.config.print_stream:
89
+ for handler in mc.env().llm_after_handlers:
90
+ handler(ctx.response)
91
+
92
+
68
93
  async def process_stream(
69
94
  async_llm_func,
70
95
  request: ChatCompletionRequest,
@@ -121,6 +146,7 @@ async def process_stream(
121
146
  except Exception as e:
122
147
  ctx.error = e
123
148
  yield make_chunk(error={"message": str(e), "type": type(e).__name__})
149
+ finish_printing_llm_response(ctx)
124
150
 
125
151
  yield make_chunk(finish_reason="error" if ctx.error else "stop")
126
152
  yield "data: [DONE]\n\n"
@@ -252,6 +278,7 @@ async def chat_completions(request: ChatCompletionRequest, raw_request: Request)
252
278
  async_llm_func = env.connections[connection]
253
279
 
254
280
  logging.info("Querying LLM... params: %s", ctx.llm_params)
281
+ print_llm_request(ctx)
255
282
  if request.stream:
256
283
  return StreamingResponse(
257
284
  process_stream(async_llm_func, request, ctx),
@@ -261,9 +288,11 @@ async def chat_completions(request: ChatCompletionRequest, raw_request: Request)
261
288
  try:
262
289
  out = await async_llm_func(request.messages, **ctx.llm_params)
263
290
  ctx.response = out
291
+ finish_printing_llm_response(ctx)
264
292
  logging.info("LLM response: %s", out)
265
293
  except Exception as e:
266
294
  ctx.error = e
295
+ finish_printing_llm_response(ctx)
267
296
  await log_non_blocking(ctx)
268
297
  error_details = f" [{type(e).__name__}]: {e}" if env.debug else ""
269
298
  logging.exception(e)
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "openai-http-proxy"
3
- version = "3.2.3"
3
+ version = "3.3.0"
4
4
  description = "OpenAI HTTP Proxy is an OpenAI-compatible http proxy server for inferencing various LLMs capable of working with Google, Anthropic, OpenAI APIs, local PyTorch inference, etc."
5
5
  readme = "README.md"
6
6
  keywords = ["llm", "large language models", "ai", "gpt", "openai", "proxy", "http", "proxy-server", "llm gateway", "openai", "anthropic", "google genai"]
@@ -35,7 +35,7 @@ documentation = "https://github.com/Nayjest/lm-proxy#readme"
35
35
  license = { file = "LICENSE" }
36
36
 
37
37
  dependencies = [
38
- "ai-microcore>=6.2.1,<7",
38
+ "ai-microcore>=6.6.1,<7",
39
39
  "fastapi>=0.136.3,<1",
40
40
  "uvicorn>=0.41.0",
41
41
  "typer>=0.24.0,<1",
@@ -1,9 +0,0 @@
1
- """JSON configuration loader."""
2
-
3
- import json
4
-
5
-
6
- def load_json_config(config_path: str) -> dict:
7
- """Loads configuration from a JSON file."""
8
- with open(config_path, "r", encoding="utf-8") as f:
9
- return json.load(f)
@@ -1,9 +0,0 @@
1
- """TOML configuration loader."""
2
-
3
- import tomllib
4
-
5
-
6
- def load_toml_config(config_path: str) -> dict:
7
- """Loads configuration from a TOML file."""
8
- with open(config_path, "rb") as f:
9
- return tomllib.load(f)