codex-as-api 0.10.0__tar.gz → 0.10.1__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 (60) hide show
  1. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/PKG-INFO +23 -4
  2. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/README.md +22 -3
  3. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/RELEASES.md +14 -0
  4. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/pyproject.toml +1 -1
  5. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/src/codex_as_api/__init__.py +1 -1
  6. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/src/codex_as_api/provider.py +9 -3
  7. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/src/codex_as_api/server.py +1 -1
  8. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/tests/test_provider.py +38 -3
  9. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/tests/test_server.py +1 -1
  10. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/.gitignore +0 -0
  11. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/LICENSE +0 -0
  12. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/THIRD_PARTY_NOTICES.md +0 -0
  13. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/config/codex-upstream-contract.json +0 -0
  14. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/config/o200k_base.tiktoken +0 -0
  15. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/config/verified-hidden-models.json +0 -0
  16. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/requirements.txt +0 -0
  17. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/rust/THIRD_PARTY_NOTICES.md +0 -0
  18. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/scripts/check_no_static_model_catalog.py +0 -0
  19. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/scripts/check_package_versions.py +0 -0
  20. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/scripts/check_registry_release.py +0 -0
  21. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/scripts/check_release_artifacts.py +0 -0
  22. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/scripts/generate_rust_third_party_notices.py +0 -0
  23. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/scripts/package_rust_release.py +0 -0
  24. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/src/codex_as_api/anthropic_adapter.py +0 -0
  25. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/src/codex_as_api/auth.py +0 -0
  26. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/src/codex_as_api/browser_login.py +0 -0
  27. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/src/codex_as_api/codex_config.py +0 -0
  28. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/src/codex_as_api/codex_version.py +0 -0
  29. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/src/codex_as_api/device_login.py +0 -0
  30. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/src/codex_as_api/messages.py +0 -0
  31. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/src/codex_as_api/model_capabilities.py +0 -0
  32. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/src/codex_as_api/o200k_tokenizer.py +0 -0
  33. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/src/codex_as_api/protocol.py +0 -0
  34. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/src/codex_as_api/reasoning_signature.py +0 -0
  35. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/src/codex_as_api/strict_json.py +0 -0
  36. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/tests/__init__.py +0 -0
  37. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/tests/conftest.py +0 -0
  38. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/tests/fixtures/o200k_base_encode_ordinary.json +0 -0
  39. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/tests/test_anthropic_adapter.py +0 -0
  40. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/tests/test_auth.py +0 -0
  41. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/tests/test_browser_login.py +0 -0
  42. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/tests/test_codex_config.py +0 -0
  43. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/tests/test_codex_version.py +0 -0
  44. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/tests/test_device_login.py +0 -0
  45. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/tests/test_login_commit_races.py +0 -0
  46. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/tests/test_login_generation.py +0 -0
  47. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/tests/test_login_http_real_store.py +0 -0
  48. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/tests/test_management_body.py +0 -0
  49. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/tests/test_messages.py +0 -0
  50. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/tests/test_model_capabilities.py +0 -0
  51. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/tests/test_no_static_model_catalog.py +0 -0
  52. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/tests/test_o200k_tokenizer.py +0 -0
  53. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/tests/test_package_versions.py +0 -0
  54. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/tests/test_protocol.py +0 -0
  55. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/tests/test_registry_release.py +0 -0
  56. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/tests/test_release_artifacts.py +0 -0
  57. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/tests/test_rust_third_party_notices.py +0 -0
  58. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/tests/test_standalone_login_api.py +0 -0
  59. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/tests/test_strict_json.py +0 -0
  60. {codex_as_api-0.10.0 → codex_as_api-0.10.1}/tests/test_ultrafast.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: codex-as-api
3
- Version: 0.10.0
3
+ Version: 0.10.1
4
4
  Summary: Use ChatGPT/Codex OAuth as a local OpenAI-compatible API server.
5
5
  Project-URL: Homepage, https://github.com/Eunho-J/codex-as-api
6
6
  Project-URL: Repository, https://github.com/Eunho-J/codex-as-api
@@ -241,6 +241,16 @@ admin bearer and is not a replacement for authentication or network controls.
241
241
  Each credential store must be owned by one server process, not shared between
242
242
  independent workers. Choose separate store paths for separate instances.
243
243
 
244
+ ### Note on OpenAI "Sign in with ChatGPT" (SIWC) preview
245
+
246
+ OpenAI's public [Sign in with ChatGPT (`chatgpt.tokens.use.direct`)](https://developers.openai.com/cookbook/articles/sign-in-with-chatgpt)
247
+ preview route (`https://api.openai.com/v1/responses` with dynamic client registration)
248
+ is intentionally kept on hold and not used as the default transport:
249
+
250
+ - Function tools on the SIWC preview route must be wrapped inside a `namespace` tool object rather than sent as top-level function definitions.
251
+ - Remote compaction (`/responses/compact`), `Responses Lite`, hosted `image_generation`, device-code login, and ChatGPT Live / Realtime WebRTC voice calls are not supported on the SIWC preview route.
252
+ - Reliable prompt cache hits on SIWC currently require reusing a persistent WebSocket (`wss://api.openai.com/v1/responses`) rather than stateless HTTP `POST /v1/responses` requests.
253
+
244
254
  ## Configuration
245
255
 
246
256
  Environment variables (Python, Rust, and TypeScript):
@@ -451,6 +461,10 @@ null, or server-tool caller variants still fail before transport.
451
461
 
452
462
  ### Identifier and cache behavior
453
463
 
464
+ For chat requests, initial system messages form `instructions`. System
465
+ messages added after conversation history starts stay at their original positions
466
+ as developer messages, so appending runtime notes preserves the earlier history prefix.
467
+
454
468
  The two compatibility facades intentionally use the similarly named fields for
455
469
  different jobs:
456
470
 
@@ -992,9 +1006,9 @@ registry setup is still required:
992
1006
  After bumping every version and passing the local gate, push the matching tag:
993
1007
 
994
1008
  ```bash
995
- python scripts/check_package_versions.py --tag v0.10.0
996
- git tag v0.10.0
997
- git push origin v0.10.0
1009
+ python scripts/check_package_versions.py --tag v0.10.1
1010
+ git tag v0.10.1
1011
+ git push origin v0.10.1
998
1012
  ```
999
1013
 
1000
1014
  ## Tests
@@ -1025,6 +1039,11 @@ npm test
1025
1039
 
1026
1040
  ## Release Notes
1027
1041
 
1042
+ ### v0.10.1
1043
+
1044
+ - Preserve mid-history `system` messages added after conversation history starts as in-place `developer` input items across Python, TypeScript, and Rust chat requests, keeping the earlier conversation history prefix stable for prompt caching while leaving remote compaction (`compact_messages`) unchanged.
1045
+ - Document current preview limitations of OpenAI's public "Sign in with ChatGPT" (`chatgpt.tokens.use.direct`) route and why the Codex OAuth transport remains the default.
1046
+
1028
1047
  ### v0.10.0
1029
1048
 
1030
1049
  - Sign in directly with ordinary browser OAuth; no Codex installation or existing
@@ -206,6 +206,16 @@ admin bearer and is not a replacement for authentication or network controls.
206
206
  Each credential store must be owned by one server process, not shared between
207
207
  independent workers. Choose separate store paths for separate instances.
208
208
 
209
+ ### Note on OpenAI "Sign in with ChatGPT" (SIWC) preview
210
+
211
+ OpenAI's public [Sign in with ChatGPT (`chatgpt.tokens.use.direct`)](https://developers.openai.com/cookbook/articles/sign-in-with-chatgpt)
212
+ preview route (`https://api.openai.com/v1/responses` with dynamic client registration)
213
+ is intentionally kept on hold and not used as the default transport:
214
+
215
+ - Function tools on the SIWC preview route must be wrapped inside a `namespace` tool object rather than sent as top-level function definitions.
216
+ - Remote compaction (`/responses/compact`), `Responses Lite`, hosted `image_generation`, device-code login, and ChatGPT Live / Realtime WebRTC voice calls are not supported on the SIWC preview route.
217
+ - Reliable prompt cache hits on SIWC currently require reusing a persistent WebSocket (`wss://api.openai.com/v1/responses`) rather than stateless HTTP `POST /v1/responses` requests.
218
+
209
219
  ## Configuration
210
220
 
211
221
  Environment variables (Python, Rust, and TypeScript):
@@ -416,6 +426,10 @@ null, or server-tool caller variants still fail before transport.
416
426
 
417
427
  ### Identifier and cache behavior
418
428
 
429
+ For chat requests, initial system messages form `instructions`. System
430
+ messages added after conversation history starts stay at their original positions
431
+ as developer messages, so appending runtime notes preserves the earlier history prefix.
432
+
419
433
  The two compatibility facades intentionally use the similarly named fields for
420
434
  different jobs:
421
435
 
@@ -957,9 +971,9 @@ registry setup is still required:
957
971
  After bumping every version and passing the local gate, push the matching tag:
958
972
 
959
973
  ```bash
960
- python scripts/check_package_versions.py --tag v0.10.0
961
- git tag v0.10.0
962
- git push origin v0.10.0
974
+ python scripts/check_package_versions.py --tag v0.10.1
975
+ git tag v0.10.1
976
+ git push origin v0.10.1
963
977
  ```
964
978
 
965
979
  ## Tests
@@ -990,6 +1004,11 @@ npm test
990
1004
 
991
1005
  ## Release Notes
992
1006
 
1007
+ ### v0.10.1
1008
+
1009
+ - Preserve mid-history `system` messages added after conversation history starts as in-place `developer` input items across Python, TypeScript, and Rust chat requests, keeping the earlier conversation history prefix stable for prompt caching while leaving remote compaction (`compact_messages`) unchanged.
1010
+ - Document current preview limitations of OpenAI's public "Sign in with ChatGPT" (`chatgpt.tokens.use.direct`) route and why the Codex OAuth transport remains the default.
1011
+
993
1012
  ### v0.10.0
994
1013
 
995
1014
  - Sign in directly with ordinary browser OAuth; no Codex installation or existing
@@ -1,5 +1,19 @@
1
1
  # Release Notes
2
2
 
3
+ ## v0.10.1
4
+
5
+ ### Preserve late system notes across Python, TypeScript and Rust chat histories
6
+
7
+ - Keep initial `system` messages in top-level `instructions`, and preserve `system`
8
+ messages appended after conversation history starts at their original positions as
9
+ `developer` input items across Python, TypeScript and Rust chat requests.
10
+ Appending per-turn runtime notes after tool results no longer mutates
11
+ `instructions` or invalidates the cached prefix of the prior conversation history.
12
+ - Remote compaction (`/v1/compact` and `/v1/messages/compact`) remains unchanged so
13
+ system directives continue to form `instructions` during compaction.
14
+ - Document current preview constraints of OpenAI's public "Sign in with ChatGPT"
15
+ (`chatgpt.tokens.use.direct`) route in `README.md`.
16
+
3
17
  ## v0.10.0
4
18
 
5
19
  ### Standalone browser login — no Codex installation required
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "codex-as-api"
7
- version = "0.10.0"
7
+ version = "0.10.1"
8
8
  description = "Use ChatGPT/Codex OAuth as a local OpenAI-compatible API server."
9
9
  readme = "README.md"
10
10
  license = { text = "Apache-2.0" }
@@ -1,3 +1,3 @@
1
1
  """codex-as-api: Use ChatGPT/Codex OAuth as a local OpenAI-compatible API server."""
2
2
 
3
- __version__ = "0.10.0"
3
+ __version__ = "0.10.1"
@@ -16,7 +16,7 @@ import urllib.request
16
16
  from collections import OrderedDict
17
17
  from collections.abc import Iterator, Sequence
18
18
  from copy import deepcopy
19
- from dataclasses import dataclass
19
+ from dataclasses import dataclass, replace
20
20
  from typing import Any, NoReturn, cast
21
21
 
22
22
  from . import __version__
@@ -1426,13 +1426,14 @@ class ChatGPTOAuthProvider:
1426
1426
  if max_tokens is not None:
1427
1427
  raise ChatGPTOAuthInvalidRequestError("max_tokens is not supported by the ChatGPT Codex OAuth transport")
1428
1428
  _reject_unsupported_stop(stop)
1429
- instructions, input_items = _split_instructions_and_input(messages)
1429
+ instructions, input_items = _split_instructions_and_input(messages, preserve_system_positions=True)
1430
1430
  snapshot, capability = _resolved_model or self.resolve_model(model)
1431
1431
  request_model = capability.slug
1432
1432
  if any(msg.reasoning_items for msg in messages):
1433
1433
  instructions, input_items = _split_instructions_and_input(
1434
1434
  messages,
1435
1435
  backend_model=request_model,
1436
+ preserve_system_positions=True,
1436
1437
  )
1437
1438
  if previous_response_id is not None:
1438
1439
  validated_previous_response_id = _validate_previous_response_id(previous_response_id)
@@ -2223,6 +2224,7 @@ def _split_instructions_and_input(
2223
2224
  messages: Sequence[Message],
2224
2225
  *,
2225
2226
  backend_model: str | None = None,
2227
+ preserve_system_positions: bool = False,
2226
2228
  ) -> tuple[str, list[dict[str, Any]]]:
2227
2229
  instructions: list[str] = []
2228
2230
  input_messages: list[Message] = []
@@ -2232,7 +2234,11 @@ def _split_instructions_and_input(
2232
2234
  part.get("prompt_cache_breakpoint") is not None for part in msg.content_parts
2233
2235
  ):
2234
2236
  _reject_prompt_cache_breakpoint(None)
2235
- instructions.append(msg.content)
2237
+ if preserve_system_positions and input_messages:
2238
+ # Hoisting late system notes changes the entire cached history prefix.
2239
+ input_messages.append(replace(msg, role=MessageRole.DEVELOPER))
2240
+ else:
2241
+ instructions.append(msg.content)
2236
2242
  else:
2237
2243
  input_messages.append(msg)
2238
2244
  return "\n\n".join(instructions), _messages_to_response_items(
@@ -471,7 +471,7 @@ def _health_error_message(exc: BaseException) -> str:
471
471
  app = FastAPI(
472
472
  title="codex-as-api",
473
473
  description="Local OpenAI-compatible API server backed by ChatGPT/Codex OAuth.",
474
- version="0.10.0",
474
+ version="0.10.1",
475
475
  )
476
476
 
477
477
 
@@ -2196,7 +2196,7 @@ def test_codex_cli_headers_include_official_originator_and_versioned_user_agent(
2196
2196
 
2197
2197
  assert headers["originator"] == "codex_cli_rs"
2198
2198
  assert headers["User-Agent"].startswith("codex_cli_rs/0.164.0 (")
2199
- assert headers["User-Agent"].endswith(") codex-as-api/0.10.0")
2199
+ assert headers["User-Agent"].endswith(") codex-as-api/0.10.1")
2200
2200
 
2201
2201
 
2202
2202
  def test_codex_cli_headers_reject_unpinned_version():
@@ -2936,7 +2936,7 @@ def test_provider_headers_include_codex_cli_headers(auth_json_factory):
2936
2936
 
2937
2937
  assert headers["originator"] == "codex_cli_rs"
2938
2938
  assert headers["User-Agent"].startswith("codex_cli_rs/0.164.0 (")
2939
- assert headers["User-Agent"].endswith(") codex-as-api/0.10.0")
2939
+ assert headers["User-Agent"].endswith(") codex-as-api/0.10.1")
2940
2940
  assert headers["Authorization"].startswith("Bearer ")
2941
2941
 
2942
2942
 
@@ -3549,6 +3549,41 @@ def test_split_instructions_multiple_system_joined():
3549
3549
  assert instructions == "Part one.\n\nPart two."
3550
3550
 
3551
3551
 
3552
+ @pytest.mark.parametrize("with_reasoning", [False, True])
3553
+ def test_responses_payload_keeps_late_system_notes_after_tool_results(with_reasoning):
3554
+ provider = ChatGPTOAuthProvider()
3555
+ messages = [
3556
+ Message(role=MessageRole.SYSTEM, content="Stable instructions."),
3557
+ Message(role=MessageRole.USER, content="Read the fixture."),
3558
+ Message(role=MessageRole.SYSTEM, content="Initial environment."),
3559
+ ]
3560
+ tools = [ToolSchema(name="Read", description="Read a file.", parameters={"type": "object"})]
3561
+ previous = None
3562
+ for turn in range(3):
3563
+ payload = provider._responses_payload( # noqa: SLF001
3564
+ messages, model="gpt-5.5", tools=tools, responses_lite=False,
3565
+ prompt_cache_key="same-session",
3566
+ )
3567
+ assert payload["instructions"] == "Stable instructions."
3568
+ assert payload["input"][-1]["role"] == "developer"
3569
+ if previous is not None:
3570
+ assert payload["input"][:len(previous["input"])] == previous["input"]
3571
+ assert payload["tools"] == previous["tools"]
3572
+ assert payload["prompt_cache_key"] == previous["prompt_cache_key"]
3573
+ if with_reasoning:
3574
+ assert sum(item.get("type") == "reasoning" for item in payload["input"]) == turn
3575
+ previous = payload
3576
+ messages.extend([
3577
+ Message(role=MessageRole.ASSISTANT, content="", tool_calls=(
3578
+ ToolCall(id=f"call_{turn}", name="Read", arguments='{"path":"fixture"}'),
3579
+ ), reasoning_items=(
3580
+ {"type": "reasoning", "encrypted_content": f"opaque_{turn}", "summary": []},
3581
+ ) if with_reasoning else ()),
3582
+ Message(role=MessageRole.TOOL, content=f"Fixture result {turn}.", tool_call_id=f"call_{turn}"),
3583
+ Message(role=MessageRole.SYSTEM, content=f"Budget remaining: {1000 - turn}."),
3584
+ ])
3585
+
3586
+
3552
3587
  @pytest.mark.parametrize("responses_lite", [False, True])
3553
3588
  def test_responses_payload_accepts_user_input_without_system_instructions(responses_lite):
3554
3589
  provider = ChatGPTOAuthProvider()
@@ -4537,7 +4572,7 @@ def test_provider_injects_dynamic_npm_version_across_catalog_responses_and_401_r
4537
4572
  for full_url, headers in observed_requests:
4538
4573
  assert full_url == "https://example.test/codex/models?client_version=0.175.2"
4539
4574
  assert headers["user-agent"].startswith("codex_cli_rs/0.175.2 (")
4540
- assert headers["user-agent"].endswith(") codex-as-api/0.10.0")
4575
+ assert headers["user-agent"].endswith(") codex-as-api/0.10.1")
4541
4576
 
4542
4577
 
4543
4578
  def test_provider_cold_version_resolver_failure_raises_typed_503(auth_json_factory, monkeypatch):
@@ -6652,7 +6652,7 @@ def test_dynamic_npm_version_resolver_updates_models_query_user_agent_and_cold_f
6652
6652
  responses_req_1 = recording_backend.requests.get(timeout=1)
6653
6653
  assert catalog_req_1["path"] == "/models?client_version=0.175.2"
6654
6654
  assert catalog_req_1["headers"]["user-agent"].startswith("codex_cli_rs/0.175.2 (")
6655
- assert catalog_req_1["headers"]["user-agent"].endswith(") codex-as-api/0.10.0")
6655
+ assert catalog_req_1["headers"]["user-agent"].endswith(") codex-as-api/0.10.1")
6656
6656
  assert responses_req_1["headers"]["user-agent"].startswith("codex_cli_rs/0.175.2 (")
6657
6657
 
6658
6658
  active_version = "0.176.0"
File without changes
File without changes