OpenAI API: Key Setup and Model Reference
Table of Contents
1. OpenAI API
You can get your API key from https://beta.openai.com/account/api-keys
You can set it in your shell environment:
export OPENAI_API_KEY=sk-...
#+end_example
#+begin_src sh :results raw
echo "API Key starts with: $(echo $OPENAI_API_KEY | cut -c1-7)..."
echo "API Key length: ${#OPENAI_API_KEY}"
API Key starts with: sk-Q27r… API Key length: 51
1.1. Models
1.1.1. Shell
curl -s -X 'GET' \
'https://api.openai.com/v1/models' \
-H 'accept: application/json' \
-H "Authorization: Bearer $OPENAI_API_KEY" \
| jq -r '.data | sort_by(-.created) | map([.id, .object, .created, .owned_by] | @tsv) | .[]'
1.1.2. Emacs Lisp
(require 'json)
(require 'url)
(let* ((url-request-method "GET")
(url-request-extra-headers
`(("Authorization" . ,(concat "Bearer " openai-api-key))
("Accept" . "application/json")))
(url "https://api.openai.com/v1/models")
(buffer (url-retrieve-synchronously url))
(response-body (with-current-buffer buffer
(goto-char (point-min))
(re-search-forward "\n\n")
(buffer-substring-no-properties (point) (point-max))))
(json-object-type 'hash-table)
(json-array-type 'list)
(json-key-type 'string)
(data (gethash "data" (json-read-from-string response-body)))
(sorted-data (sort data (lambda (a b)
(> (gethash "created" a)
(gethash "created" b))))))
(with-output-to-string
(princ "id\tobject\tcreated\towned_by\n")
(dolist (item sorted-data)
(princ (format "%s\t%s\t%s\t%s\n"
(gethash "id" item)
(gethash "object" item)
(gethash "created" item)
(gethash "owned_by" item))))))
1.1.3. Rest
GET https://api.openai.com/v1/models
Accept: application/json
Authorization: Bearer {{{api-key}}}
GET https://api.openai.com/v1/models
Accept: application/json
Authorization: Bearer :api-key
2. AI Model Outputs
2.1. Create Output Directory
mkdir -p ai_model_outputs
echo "JSON outputs will be saved in the 'ai_model_outputs' directory."
JSON outputs will be saved in the 'ai_model_outputs' directory.
2.2. OpenAI Models
echo "OpenAI API Key starts with: $(echo $OPENAI_API_KEY | cut -c1-7)..."
echo "OpenAI API Key length: ${#OPENAI_API_KEY}"
echo "OpenAI Models:"
curl -s -H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
https://api.openai.com/v1/models |
tee ai_model_outputs/openai_models.json | jq '.data[].id' | head
echo "Model structure (keys of the first model):"
jq -r '.[0] | keys[]' ai_model_outputs/huggingface_models.json
OpenAI API Key starts with: ... OpenAI API Key length: 0 OpenAI Models: Model structure (keys of the first model): _id createdAt downloads id library_name likes modelId pipeline_tag private tags
2.3. Anthropic Models
echo "Anthropic API Key starts with: $(echo $ANTHROPIC_API_KEY | cut -c1-7)..."
echo "Anthropic API Key length: ${#ANTHROPIC_API_KEY}"
echo "Anthropic Models:"
curl -s -H "x-api-key: $ANTHROPIC_API_KEY" \
-H "Content-Type: application/json" \
https://api.anthropic.com/v1/models |
tee ai_model_outputs/anthropic_models.json | jq '.models[].name'
Anthropic API Key starts with: ... Anthropic API Key length: 0 Anthropic Models:
2.4. Google Gemini Models
echo "Google API Key starts with: $(echo $GOOGLE_API_KEY | cut -c1-7)..."
echo "Google API Key length: ${#GOOGLE_API_KEY}"
echo "Google Gemini Models:"
curl -s -H "Authorization: Bearer $GOOGLE_API_KEY" \
-H "Content-Type: application/json" \
"https://generativelanguage.googleapis.com/v1beta/models?key=$GOOGLE_API_KEY" |
tee ai_model_outputs/google_gemini_models.json | jq '.models[].name'
Google API Key starts with: ... Google API Key length: 0 Google Gemini Models:
2.5. Phind Models
echo "Phind Models:"
echo "Please check https://www.phind.com/api for the latest information on available models." |
tee ai_model_outputs/phind_info.txt
Phind Models: Please check https://www.phind.com/api for the latest information on available models.
2.6. Meta AI Models
echo "Meta AI Models:"
echo "LLaMA models are typically accessed through third-party providers or self-hosted solutions." |
tee ai_model_outputs/meta_ai_info.txt
Meta AI Models: LLaMA models are typically accessed through third-party providers or self-hosted solutions.
2.7. Cohere Models
echo "Cohere API Key starts with: $(echo $COHERE_API_KEY | cut -c1-7)..."
echo "Cohere API Key length: ${#COHERE_API_KEY}"
echo "Cohere Models:"
curl -s -H "Authorization: Bearer $COHERE_API_KEY" \
-H "Content-Type: application/json" \
https://api.cohere.ai/v1/models |
tee ai_model_outputs/cohere_models.json | jq '.models[].name'
Cohere API Key starts with: ... Cohere API Key length: 0 Cohere Models:
2.8. AI21 Labs Models
echo "AI21 API Key starts with: $(echo $AI21_API_KEY | cut -c1-7)..."
echo "AI21 API Key length: ${#AI21_API_KEY}"
echo "AI21 Labs Models:"
curl -s -H "Authorization: Bearer $AI21_API_KEY" \
-H "Content-Type: application/json" \
https://api.ai21.com/studio/v1/models |
tee ai_model_outputs/ai21_models.json | jq '.models[].name'
AI21 API Key starts with: ... AI21 API Key length: 0 AI21 Labs Models:
2.9. Hugging Face Models
echo "Hugging Face API Key starts with: $(echo $HUGGINGFACE_API_KEY | cut -c1-7)..."
echo "Hugging Face API Key length: ${#HUGGINGFACE_API_KEY}"
echo "Fetching Hugging Face Models (top models by downloads)..."
curl -s -H "Authorization: Bearer $HUGGINGFACE_API_KEY" \
"https://huggingface.co/api/models?sort=downloads&direction=-1&limit=100" \
> ai_model_outputs/huggingface_models.json
echo "Number of models retrieved:"
jq '. | length' ai_model_outputs/huggingface_models.json
echo "Top 5 model names:"
jq -r '.[0:5][].modelId' ai_model_outputs/huggingface_models.json
echo "Model structure (keys of the first model):"
jq -r '.[0] | keys[]' ai_model_outputs/huggingface_models.json
Hugging Face API Key starts with: ... Hugging Face API Key length: 0 Fetching Hugging Face Models (top models by downloads)... Number of models retrieved: 100 Top 5 model names: sentence-transformers/all-MiniLM-L6-v2 cross-encoder/ms-marco-MiniLM-L6-v2 BAAI/bge-small-en-v1.5 google/electra-base-discriminator sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2 Model structure (keys of the first model): _id createdAt downloads id library_name likes modelId pipeline_tag private tags