You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+45-4Lines changed: 45 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -81,17 +81,58 @@ Robot models are detected using a heuristic. See the section below on how to con
81
81
82
82
## Prompting / Scene Generation Examples
83
83
84
-
You can conveniently generate a MuJoCo scene from a natural-language prompt (requires an OpenAI API key):
84
+
You can conveniently generate a MuJoCo scene from a natural-language prompt using OpenAI or OpenRouter.
85
+
86
+
You can either export your keys in the shell or place them in a `.env` file in the working directory (or any parent directory). The CLI loads `.env` automatically on startup:
87
+
88
+
```bash
89
+
cp .env.example .env
90
+
# Then edit `.env` and set OPENAI_API_KEY=... and/or OPENROUTER_API_KEY=...
91
+
```
92
+
93
+
Exported environment variables take precedence over values in `.env`.
94
+
95
+
### Using OpenAI
85
96
86
97
```bash
87
98
# Set this to your API key
88
99
export OPENAI_API_KEY=...
89
100
# Generate a scene from a prompt string
90
-
mjprompt
101
+
mjprompt "A detailed kitchen."
102
+
```
103
+
104
+
### Using OpenRouter
105
+
106
+
OpenRouter allows you to use various models beyond OpenAI, including many free models.
107
+
108
+
```bash
109
+
# Set this to your OpenRouter API key
110
+
export OPENROUTER_API_KEY=...
91
111
92
-
# Edit the generated scene.
93
-
mjedit examples/prompt/scene_coffee_shop.xml
112
+
# Generate a scene using a specific model via OpenRouter
113
+
mjprompt --provider openrouter --model google/gemini-flash-1.5:free "A cozy living room with a sofa and coffee table."
114
+
115
+
# Verified working example with GPT-5 Codex via OpenRouter
116
+
mjprompt --provider openrouter --model openai/gpt-5-codex "Output ONLY a valid MuJoCo XML document with root tag <mujoco> for a red cube on a gray floor."
117
+
```
118
+
119
+
If both `OPENAI_API_KEY` and `OPENROUTER_API_KEY` are set, the editor defaults to OpenAI unless `--provider openrouter` is specified. If only `OPENROUTER_API_KEY` is set, it will automatically fallback to OpenRouter.
120
+
121
+
Tested OpenRouter models include `openrouter/free`, `openai/gpt-5-codex`, `qwen/qwen3.6-plus:free`, `nvidia/nemotron-3-super-120b-a12b:free`, `openai/gpt-oss-120b:free`, and `openai/gpt-oss-20b:free`. Availability may still vary with your OpenRouter account and privacy settings.
122
+
123
+
#### Troubleshooting OpenRouter
124
+
125
+
- If a model returns `404 Not Found`, check your OpenRouter privacy/data policy settings and confirm that the model is enabled for your account.
126
+
- Some free models may occasionally return non-MuJoCo XML or malformed output; retrying with a stricter prompt or another tested model such as `openai/gpt-5-codex` usually helps.
127
+
- If generation fails entirely, verify that `OPENROUTER_API_KEY` is set correctly in your shell or `.env` file.
128
+
129
+
To quickly validate your setup, this tested command runs the OpenRouter integration checks:
130
+
131
+
```bash
132
+
set -a &&. ./.env &&set +a
133
+
PYTHONPATH=src uv run pytest -q examples/test_openrouter.py -s
94
134
```
135
+
95
136
Loading a generated scene might not work out of the box in all cases. Generated scenes can have inconsistencies in geometry, but can be easily edited.
0 commit comments