Home / AI & GenAI

AI & GenAICheat sheetBeginner

OCI Generative AI CLI cheat sheet: models, test chat calls, embeddings, dedicated clusters and endpoints

The oci CLI commands you need to list Generative AI models, send a test chat or embedding call, and check dedicated AI clusters, endpoints and retirement dates.

Deepak Bhardwaj7 min read

Applies toOCI Generative AI service; OCI CLI 3.x (oci generative-ai and oci generative-ai-inference)

Goal

You want to answer quick questions from a terminal. Which models can I call in this region? Does a chat call work with my credentials? Is our dedicated cluster healthy? When does this model retire? This sheet covers the oci CLI commands for each.

The service has two command groups:

Group Use it for
oci generative-ai Management: models, dedicated AI clusters, endpoints, private endpoints, work requests
oci generative-ai-inference Calling models: chat, embeddings, rerank, guardrails

Subcommands get added often. Run oci generative-ai -h and oci generative-ai-inference -h to see what your CLI version has, and upgrade the CLI if a command in this sheet is missing.

Setup

oci --version
export C=ocid1.compartment.oc1..aaaa...          # compartment that holds or uses GenAI
export OCI_CLI_REGION=us-chicago-1               # a region where Generative AI is available

The inference endpoint is worked out from the region. If you need a specific endpoint, pass the global --endpoint flag:

--endpoint https://inference.generativeai.us-chicago-1.oci.oraclecloud.com

Your group needs an IAM policy such as allow group genai-users to use generative-ai-family in compartment <name>. For 401/404 errors and region issues, see the OCI Generative AI policies and errors post.

Models

List models you can call

oci generative-ai model-collection list-models -c "$C" --all \
  --query 'data.items[].{name:"display-name", vendor:vendor, version:version, caps:capabilities, state:"lifecycle-state"}' \
  --output table

Filter by capability or vendor:

oci generative-ai model-collection list-models -c "$C" --all --capability CHAT
oci generative-ai model-collection list-models -c "$C" --all --capability TEXT_EMBEDDINGS
oci generative-ai model-collection list-models -c "$C" --all --vendor meta --lifecycle-state ACTIVE

Other --capability values include TEXT_RERANK and FINE_TUNE. The list depends on the CLI version, so check -h.

Show one model and its retirement dates

oci generative-ai model get --model-id ocid1.generativeaimodel.oc1... --output json

Look for the deprecation and retirement time fields in the output. On-demand and dedicated serving can have different retirement dates. Field names vary by CLI and API version, so read the full JSON once before you script against it.

A weekly report of models with a deprecation date:

oci generative-ai model-collection list-models -c "$C" --all --output json |
  jq -r '.data.items[] | select(."time-deprecated" != null) | [."display-name", .version, ."time-deprecated"] | @tsv'

Warning

On-demand models are retired on Oracle's schedule. An app that hard-codes a model name stops working on the retirement date. Track these dates the same way you track certificate expiry.

Test chat calls

Quickest: on-demand chat with a request file

Generate a template, then fill it in:

oci generative-ai-inference chat-result chat-on-demand-serving-mode \
  --generate-param-json-input chat-request > chat-request.json

A minimal generic-format request for Meta, OpenAI-compatible and most non-Cohere models:

{
  "apiFormat": "GENERIC",
  "messages": [
    { "role": "USER", "content": [ { "type": "TEXT", "text": "Reply with the word pong." } ] }
  ],
  "maxTokens": 20,
  "temperature": 0
}
oci generative-ai-inference chat-result chat-on-demand-serving-mode \
  -c "$C" \
  --serving-mode-model-id "<model OCID or name from list-models>" \
  --chat-request file://chat-request.json

Pull out just the answer and the token usage (the response shape differs between generic and Cohere formats; check with --output json first):

... --query 'data."chat-response".choices[0].message.content[0].text' --raw-output
... --query 'data."chat-response".usage'

Cohere models use the Cohere request format ("apiFormat": "COHERE" with a message string). There's a separate chat-result chat-cohere-chat-request subcommand for it.

Inline flags with a serving-mode object

chat-generic-chat-request takes the request fields as flags and the model as a --serving-mode object:

oci generative-ai-inference chat-result chat-generic-chat-request \
  -c "$C" \
  --serving-mode '{"servingType":"ON_DEMAND","modelId":"<model OCID or name>"}' \
  --chat-request-messages '[{"role":"USER","content":[{"type":"TEXT","text":"Reply with pong."}]}]' \
  --chat-request-max-tokens 20 \
  --chat-request-temperature 0

To call a model hosted on your own dedicated cluster, change the serving mode:

--serving-mode '{"servingType":"DEDICATED","endpointId":"ocid1.generativeaiendpoint.oc1..."}'

Useful extra flags: --chat-request-top-p, --chat-request-seed, --chat-request-is-stream and --chat-request-reasoning-effort (only for models that support it).

Tip

A fixed prompt with maxTokens 20 and temperature 0 makes a cheap smoke test. Run it from the same network and identity as the app to check IAM, region and private endpoint routing in one go.

Embeddings

oci generative-ai-inference embed-text-result embed-text \
  -c "$C" \
  --serving-mode '{"servingType":"ON_DEMAND","modelId":"<embedding model OCID or name>"}' \
  --inputs '["How do I reset a VPN token?","VPN token reset procedure"]' \
  --input-type SEARCH_QUERY \
  --truncate END \
  --query 'data.embeddings[0] | length(@)'

That last --query prints the vector dimension. Check it against your vector index dimension before a bulk load. Use --input-type SEARCH_DOCUMENT when you index content and SEARCH_QUERY for user questions. Some models also accept --output-dimensions and --embedding-types. Check the model's documentation.

Each input has a token limit. Use --truncate END to stop over-long inputs failing, or NONE if you'd rather get an error than lose text silently.

Dedicated AI clusters

oci generative-ai dedicated-ai-cluster-collection list-dedicated-ai-clusters -c "$C" --all \
  --query 'data.items[].{name:"display-name", type:type, units:"unit-count", shape:"unit-shape", state:"lifecycle-state"}' \
  --output table

oci generative-ai dedicated-ai-cluster get --dedicated-ai-cluster-id ocid1.generativeaidedicatedaicluster.oc1...

The lifecycle states are ACTIVE, CREATING, UPDATING, NEEDS_ATTENTION, FAILED, DELETING and DELETED. Alert on NEEDS_ATTENTION and FAILED:

oci generative-ai dedicated-ai-cluster-collection list-dedicated-ai-clusters -c "$C" --all \
  --lifecycle-state NEEDS_ATTENTION --query 'data.items[]."display-name"'

Caution

Dedicated AI clusters are billed while they exist, and each has a minimum commitment. Deleting one also breaks every endpoint on it. Check the current pricing and commitment terms before you create or delete one, and never delete one from a script without a confirmation step.

Endpoints

oci generative-ai endpoint-collection list-endpoints -c "$C" --all \
  --query 'data.items[].{name:"display-name", id:id, model:"model-id", cluster:"dedicated-ai-cluster-id", state:"lifecycle-state"}' \
  --output table

oci generative-ai endpoint get --endpoint-id ocid1.generativeaiendpoint.oc1...

Endpoints that go through a private endpoint can be filtered with --generative-ai-private-endpoint-id. If an app gets timeouts only from inside the VCN, check the private endpoint and its DNS before blaming the model:

oci generative-ai generative-ai-private-endpoint-collection -h

Work requests

Creating, updating and deleting clusters and endpoints runs as asynchronous work requests. When something sits in CREATING or UPDATING for too long:

oci generative-ai work-request -h
oci generative-ai work-request-error -h
oci generative-ai work-request-log-entry -h

Use the work request ID from the create or update response. The error and log entries usually say why it stalled, for example capacity or a service limit. For limits, check the current values in the console or with oci limits value list --service-name <name> -c <tenancy OCID>. Find the service name with oci limits service list -c <tenancy OCID>.

Quick symptom map

Symptom First command
"Model not found" from the app model-collection list-models --capability CHAT in the app's region
Chat works in console, fails in app On-demand smoke test with the app's identity and --endpoint
Vector dimension mismatch embed-text ... --query 'data.embeddings[0] | length(@)'
Dedicated endpoint returns errors list-dedicated-ai-clusters --lifecycle-state NEEDS_ATTENTION
Cluster stuck creating work-request-error for its work request

Prevent it next time

  • Keep the chat and embedding smoke tests in a scheduled job per region and alert when they fail.
  • Run the deprecation-date report weekly and open tickets well before each retirement.
  • Store model OCIDs or names in config, not code, so a model swap doesn't need a release.
  • Pin the OCI CLI version in your ops image and recheck this sheet's commands with -h after each upgrade.