HackerReposA FIELD GUIDE TO OPEN SOURCE
ProSponsor the shelf♧ 0
← Back to top all-time
openai
openai-python
Python2023–2026
openai / openai-python

openai-python

The official Python library for the OpenAI API

32Distinct people
38Mentions
1Explicit recommenders
32.1KGitHub stars
REPOSITORY AT A GLANCE

What to know before exploring

What it is

The official Python library for the OpenAI API

GitHub

Where it is used

  • Home Assistant — The LiteLLM integration allows you to use a LiteLLM proxy as a conversation agent or speech-to-text service in Home Assistant. The integration calls openai.AsyncOpenAI. Source
  • Home Assistant — The llama.cpp integration allows you to use a local or remote server that implements the OpenAI-compatible chat completions API as a conversation agent in Home Assistant. The integration calls openai.AsyncOpenAI.chat.completions.create. Source
  • 2 more documented examples

What people are saying

They're pretty bad about fixing issues it seems. My favorite is #2472 which they demonstrated "fixing" on stage on the release of GPT 5, but the ticket is still open and the…

drakythe used a recommendation phrase. One indexed comment matches. This is a phrase match, not a verdict.

No classified warning is attached to this page. Read the discussions before treating silence as approval.

Also in these discussions

Mentioned in the same Hacker News threads. That is not proof they are substitutes.

This week on Hacker News

Nov 7–Nov 14 UTC · Direct repository links and separately labeled related project stories. Indexed through 11/14/2026, 6:01:08 PM UTC.

No direct repository links were found in the indexed HN discussions over the past seven days. Older discussions are available below.

Mentions over time

HN mentions by year38 dated mentions

Observed mentions: 2023-03-01 19:32:02 UTC to 2026-10-19 14:59:44 UTC.

051015202023-01-01 00:00:00 UTC to 2024-01-01 00:00:00 UTC (exclusive): 20 mentions; 6 submissions, 14 comments20232024-01-01 00:00:00 UTC to 2025-01-01 00:00:00 UTC (exclusive): 4 mentions; 2 submissions, 2 comments20242025-01-01 00:00:00 UTC to 2026-01-01 00:00:00 UTC (exclusive): 7 mentions; 1 submissions, 6 comments2026-01-01 00:00:00 UTC to 2027-01-01 00:00:00 UTC (exclusive): 7 mentions; 2 submissions, 5 comments. Incomplete calendar period.2026*

* An incomplete calendar period is marked with an outlined bar. Its count is not directly comparable with a full period.

Counts come from the repository’s dated source evidence. Index cutoff: 2026-11-02 08:16:59 UTC.

View mention counts and date ranges
UTC ranges include their start and exclude their end. Select a period to filter the source evidence.
PeriodStart (UTC)End (exclusive, UTC)MentionsSubmissionsComments
20232023-01-01 00:00:00 UTC2024-01-01 00:00:00 UTC20614
20242024-01-01 00:00:00 UTC2025-01-01 00:00:00 UTC422
20252025-01-01 00:00:00 UTC2026-01-01 00:00:00 UTC716
2026 (partial)2026-01-01 00:00:00 UTC2027-01-01 00:00:00 UTC725

From the project README

An excerpt from the repository, fetched Nov 13, 2026.

Read the project’s introduction
OpenAI Python API library The OpenAI Python library provides convenient access to the OpenAI REST API from any Python 3.10+ application. The library includes type definitions for all request params and response fields, and offers both synchronous and asynchronous clients powered by HTTPX2. It is generated from our OpenAPI specification. Documentation The REST API documentation can be found on platform.openai.com. The full API of this library can be found in api.md. Installation # install from PyPI pip install openai Usage The full API of this library can be found in api.md. The primary API for interacting with OpenAI models is the Responses API. You can generate text from the model with the code below. import os from openai import OpenAI client = OpenAI( # This is the default and can be omitted api_key=os.environ.get("OPENAI_API_KEY"), ) response = client.responses.create( model="gpt-5.5", instructions="You are a coding assistant that talks like a pirate.", input="How do I check if a Python object is an instance of a class?", ) print(response.output_text) The previous standard (supported indefinitely) for generating text is the Chat Completions API. You can use that API to generate text from the model with the code below. from openai import OpenAI client = OpenAI() completion = client.chat.completions.create( model="gpt-5.5", messages=[ {"role": "developer", "content": "Talk like a pirate."}, { "role": "user", "content": "How do I check if a Python object is an instance of a class?", }, ], ) print(completion.choices[0].message.content) While you can provide an api_key keyword argument, we recommend using python-dotenv to add OPENAI_API_KEY="My API Key" to your .env file so that your API key is not stored in source control. Get an API key here. Workload Identity Authentication For secure, automated environments like cloud-managed Kubernetes, Azure, and Google Cloud Platform, you can use workload identity authentication with short-lived tokens from cloud identity providers instead of long-lived API keys. Kubernetes (service account tokens) from openai import OpenAI from openai.auth import k8s_service_account_token_provider client = OpenAI( workload_identity={ "identity_provider_id": "idp-123", "service_account_id": "sa-456", "provider": k8s_service_account_token_provider("/var/run/secrets/kubernetes.io/serviceaccount/token"), }, ) response = client.chat.completions.create( model="gpt-5.5", messages=[{"role": "user", "content": "Hello!"}], ) Azure (managed identity) from openai import OpenAI from openai.auth import azure_managed_identity_token_provider client = OpenAI( workload_identity={ "identity_provider_id": "idp-123", "service_account_id": "sa-456", "provider": azure_managed_identity_token_provider( resource="https://management.azure.com/", ), }, ) Google Cloud Platform (compute engine metadata) from openai import OpenAI from openai.auth import gcp_id_token_provider client = OpenAI( workload_identity={ "identity_provider_id": "idp-123", "service_account_id": "sa-456", "provider": gcp_id_token_provider(audience="https://api.openai.com/v1"), }, ) Custom subject token provider from openai import OpenAI def get_custom_token() -> str: return "your-jwt-token" client = OpenAI( workload_identity={ "identity_provider_id": "idp-123", "service_account_id": "sa-456", "provider": { "token_type": "jwt", "get_token": get_custom_token, }, } ) You can also customize the token refresh buffer (default is 1200 seconds (20 minutes) before expiration): from openai import OpenAI from openai.auth import k8s_service_account_token_provider client = OpenAI( workload_identity={ "identity_provider_id": "idp-123", "service_account_id": "sa-456", "provider": k8s_service_account_token_provider("/var/token"), "refresh_buffer_seconds": 120.0, } ) X.509 workload identity (mutual TLS) For X.509 workload identity federation, configure the client certificate and server trust on an HTTPX2 client, then pass only the identity-provider and service-account IDs to the SDK: import os import ssl from openai import OpenAI, DefaultHttpx2Client from openai.auth import x509_workload_identity tls_context = ssl.create_default_context( cafile=os.getenv("OPENAI_MTLS_CA_BUNDLE"), ) tls_context.load_cert_chain( certfile=os.environ["OPENAI_MTLS_CERTIFICATE_CHAIN"], keyfile=os.environ["OPENAI_MTLS_PRIVATE_KEY"], password=os.getenv("OPENAI_MTLS_PRIVATE_KEY_PASSWORD"), ) client = OpenAI( workload_identity=x509_workload_identity( identity_provider_id=os.environ["OPENAI_IDENTITY_PROVIDER_ID"], service_account_id=os.environ["OPENAI_SERVICE_ACCOUNT_ID"], # refresh_buffer_seconds=120.0, ), http_client=DefaultHttpx2Client( verify=tls_context, follow_redirects=False, ), ) X.509 mode defaults to https://mtls.api.openai.com/v1 when neither base_url nor OPENAI_BASE_URL is set. The same configured HTTP client presents its certificate to the fixed mTLS token-exchange endpoint and to the API. Tokens are exchanged lazily, cached, and refreshed automatically. Certificate files, private keys, passwords, server trust, proxies, and rotation remain application and transport concerns. X.509 API requests require HTTPS and must stay on the configured API origin. The effective HTTP Host authority must match that origin. Provider API-key and proxy-only headers cannot be sent to the API alongside X.509 authentication. Token exchanges do not inherit API request hooks, authentication, or cookies. Identity settings are captured when the client is constructed; create a new client to change the identity. Azure clients do not support X.509 workload identity. For asynchronous req
Read the full README on GitHub

What Hacker News says

20 sources
There are no lower-level prompts than the ones described in the link. If you're asking about how the model sees the context - the messages are formatted using ChatML [1] which is a format with tokens to denote messages with their roles (and optional names) in the chat context, so it can clearly differentiate between different messages. To put it more clearly, a conversation with the official ChatGPT frontend might look like this in API terms of messages: {"role": "system", "content": "You are ChatGPT, a large language model trained by OpenAI, based on the GPT-4 architecture.\nKnowledge cutoff: 2022-01\nCurrent date: 2023-10-11\nImage input capabilities: Enabled"} {"role": "user", "content": "Hi!"} {"role": "assistant", "content": "Hello! How can I assist you today?"} You can see how it would look in the end with Tiktokenizer [2] - https:/
Read the rest
/i.imgur.com/ZLJctvn.png. And yeah, you don't have control over ChatML over the ChatCompletion API - I guess the reason they don't allow you to is because of issues with jailbreaks/safety. [1] https://github.com/openai/openai-python/blob/main/chatml.md [2] https://tiktokenizer.vercel.app/
In ChatGPT’s system prompts
There is an ongoing bug[1] with OpenAI's API, where it stops streaming responses after exactly 5 minutes. When I first came across the issue, I debugged it by writing a prompt along these lines: > Output every number from 1 to 10,000 in written form (e.g. "one", "two", etc.). Respond with one number per line in numeric order. As expected, the API would begin counting every number just as I asked. This would continue until exactly 5 minutes, when the stream would abruptly halt. Using this technique I was able to identify the bug. Every few weeks I run this test again to see if it's fixed (it broke something in production for me), but the bug remains open. However, after a couple of months, the exact same test became useless. The model began taking "shortcuts", and would respond along these lines: > four hundred and twenty eight > fo
Read the rest
ur hundred and twenty nine > [...] > nine thousand nine hundred and ninety eight > nine thousand nine hundred and ninety nine > ten thousand Yep, it literally started just writing "[...]" and skipped all the way to the end. When instructional determinism is reduced like this, it's impossible to say it's not getting worse :( [1] https://github.com/openai/openai-python/issues/399
In GPT-4 is not getting worse
SQL injections are preventable by either 1) escaping input (so that your query and the input continue to come in a single stream), or 2) sending the query out-of-band, using prepared statements with placeholders Converting this situation to AI, perhaps 2) can be done with https://github.com/openai/openai-python/blob/main/chatml.md, but if you were stuck with an unstructured text input and had to do 1), how would you escape the untrusted user input?
In Anti-recruiter prompt injection attack in LinkedIn profile

Showing the 15 most recent of 20 sources. Enable JavaScript to search and browse every indexed mention.

MAKE YOURSELF AT HOME

A few shortcuts

/
Search the collection
?
Open this guide
Esc
Close dialogs and navigation

Your saved repositories and interests stay in this browser.