Replies: 1 comment
ChatGPT Codex OAuth で Responses API を呼ぶ最小サンプル
from pathlib import Path
from openai import OpenAI
from openai.types.responses import ResponseTextDeltaEvent
from pydantic import BaseModel
class Tokens(BaseModel):
access_token: str
account_id: str
class Auth(BaseModel):
tokens: Tokens
path = Path.home().joinpath(".codex", "auth.json")
auth = Auth.model_validate_json(path.read_bytes())
client = OpenAI(
api_key=auth.tokens.access_token,
base_url="https://chatgpt.com/backend-api/codex",
default_headers={
"ChatGPT-Account-ID": auth.tokens.account_id,
},
)
stream = client.responses.create(
model="gpt-5.5",
reasoning={"effort": "low"},
instructions="You are a helpful assistant.",
input=[
{
"role": "user",
"content": "What was a positive news story from today?",
},
],
tools=[{"type": "web_search"}],
store=False,
stream=True,
)
for event in stream:
match event:
case ResponseTextDeltaEvent():
print(event.delta, end="", flush=True)
case _:
pass
else:
print() |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Today I Learned ...
All reactions