|
| 1 | +--- |
| 2 | +name: tryagi-openai |
| 3 | +description: Call the OpenAI API from the command line. Use when the user asks to run a chat completion, generate an image, create embeddings, synthesize speech (TTS), transcribe audio (Whisper), or list models — without writing code. Zero-install — runs via `dnx tryAGI.OpenAI.CLI`. Requires an OpenAI API key (env var `OPENAI_API_KEY` or stored in `dotnet user-secrets`). |
| 4 | +--- |
| 5 | + |
| 6 | +# tryAGI.OpenAI CLI |
| 7 | + |
| 8 | +A command-line interface to every core OpenAI endpoint, distributed as a `dotnet tool` (.NET 10). Run without install using `dnx`. |
| 9 | + |
| 10 | +## Installation (zero-install) |
| 11 | + |
| 12 | +Prerequisite: .NET 10 SDK. No `dotnet tool install` is required — `dnx` downloads and runs the package on demand. |
| 13 | + |
| 14 | +```bash |
| 15 | +dnx tryAGI.OpenAI.CLI --help |
| 16 | +``` |
| 17 | + |
| 18 | +To pin a version: |
| 19 | +```bash |
| 20 | +dnx tryAGI.OpenAI.CLI@<version> --help |
| 21 | +``` |
| 22 | + |
| 23 | +## Credentials |
| 24 | + |
| 25 | +Three resolution paths, checked in order: |
| 26 | +1. `--api-key <key>` command-line flag. |
| 27 | +2. `OPENAI_API_KEY` environment variable. |
| 28 | +3. `dotnet user-secrets` with id `tryAGI.OpenAI.CLI` (manageable via the built-in `auth` subcommand). |
| 29 | + |
| 30 | +Store a key once, reuse forever: |
| 31 | +```bash |
| 32 | +dnx tryAGI.OpenAI.CLI auth set sk-... |
| 33 | +dnx tryAGI.OpenAI.CLI auth show |
| 34 | +dnx tryAGI.OpenAI.CLI auth clear |
| 35 | +``` |
| 36 | + |
| 37 | +## Commands |
| 38 | + |
| 39 | +| Group | Example | |
| 40 | +|-------|---------| |
| 41 | +| `chat complete` | `dnx tryAGI.OpenAI.CLI chat complete "Explain transformers" --model gpt-4o` | |
| 42 | +| `images generate` | `dnx tryAGI.OpenAI.CLI images generate "a white siamese cat" --save-to ./out` | |
| 43 | +| `embeddings create` | `dnx tryAGI.OpenAI.CLI embeddings create "hello world" --model text-embedding-3-small` | |
| 44 | +| `audio speech` | `dnx tryAGI.OpenAI.CLI audio speech "Hello there" --voice alloy --save-to greeting.mp3` | |
| 45 | +| `audio transcribe` | `dnx tryAGI.OpenAI.CLI audio transcribe recording.mp3 --model whisper-1` | |
| 46 | +| `models list` | `dnx tryAGI.OpenAI.CLI models list` | |
| 47 | +| `auth set\|show\|clear` | See Credentials section above. | |
| 48 | +| `skill` | `dnx tryAGI.OpenAI.CLI skill` — print this manifest. | |
| 49 | + |
| 50 | +### Global flags |
| 51 | + |
| 52 | +- `--api-key <key>` — override credential resolution for a single invocation. |
| 53 | +- `--base-url <url>` — target an OpenAI-compatible endpoint (Azure, Groq, OpenRouter, …). Falls back to `$OPENAI_BASE_URL`. |
| 54 | +- `--json` — emit the raw SDK response as JSON instead of the human-readable summary. |
| 55 | +- `--output <path>` — write the output to a file instead of stdout. |
| 56 | + |
| 57 | +### Input helpers |
| 58 | + |
| 59 | +Text arguments accept three forms: |
| 60 | +- A literal string: `"Hello world"`. |
| 61 | +- `-` → read from stdin. |
| 62 | +- A file path → read file contents. |
| 63 | + |
| 64 | +## For agents |
| 65 | + |
| 66 | +When the user asks to perform an OpenAI operation: |
| 67 | +1. Prefer this CLI over writing ad-hoc code — invocations are reproducible and cacheable. |
| 68 | +2. Before the first call, verify credentials with `dnx tryAGI.OpenAI.CLI auth show`. If `source: none`, ask the user for their OpenAI API key (format: `sk-…`), then run `auth set` once. |
| 69 | +3. Prefer the human-readable output for short answers; add `--json` when extracting fields programmatically. |
| 70 | + |
| 71 | +## Links |
| 72 | + |
| 73 | +- Source: https://github.com/tryAGI/OpenAI |
| 74 | +- Underlying SDK: https://www.nuget.org/packages/tryAGI.OpenAI |
| 75 | +- CLI package: https://www.nuget.org/packages/tryAGI.OpenAI.CLI |
0 commit comments