-
Notifications
You must be signed in to change notification settings - Fork 92
feat(coder-labs/modules/codex): add support for aibridge #655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
007421f
667965e
5eecdbb
e9c9c7d
6c26ff8
956f742
b31c793
5ee430a
9bf3761
0d96c54
8da4a4a
4fb9b25
af316b6
628b5b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,7 +3,7 @@ display_name: Codex CLI | |||||||||||
| icon: ../../../../.icons/openai.svg | ||||||||||||
| description: Run Codex CLI in your workspace with AgentAPI integration | ||||||||||||
| verified: true | ||||||||||||
| tags: [agent, codex, ai, openai, tasks] | ||||||||||||
| tags: [agent, codex, ai, openai, tasks, aibridge] | ||||||||||||
| --- | ||||||||||||
|
|
||||||||||||
| # Codex CLI | ||||||||||||
|
|
@@ -13,7 +13,7 @@ Run Codex CLI in your workspace to access OpenAI's models through the Codex inte | |||||||||||
| ```tf | ||||||||||||
| module "codex" { | ||||||||||||
| source = "registry.coder.com/coder-labs/codex/coder" | ||||||||||||
| version = "4.0.0" | ||||||||||||
| version = "4.1.0" | ||||||||||||
| agent_id = coder_agent.example.id | ||||||||||||
| openai_api_key = var.openai_api_key | ||||||||||||
| workdir = "/home/coder/project" | ||||||||||||
|
|
@@ -32,7 +32,7 @@ module "codex" { | |||||||||||
| module "codex" { | ||||||||||||
| count = data.coder_workspace.me.start_count | ||||||||||||
| source = "registry.coder.com/coder-labs/codex/coder" | ||||||||||||
| version = "4.0.0" | ||||||||||||
| version = "4.1.0" | ||||||||||||
| agent_id = coder_agent.example.id | ||||||||||||
| openai_api_key = "..." | ||||||||||||
| workdir = "/home/coder/project" | ||||||||||||
|
|
@@ -52,7 +52,7 @@ data "coder_task" "me" {} | |||||||||||
|
|
||||||||||||
| module "codex" { | ||||||||||||
| source = "registry.coder.com/coder-labs/codex/coder" | ||||||||||||
| version = "4.0.0" | ||||||||||||
| version = "4.1.0" | ||||||||||||
| agent_id = coder_agent.example.id | ||||||||||||
| openai_api_key = "..." | ||||||||||||
| ai_prompt = data.coder_task.me.prompt | ||||||||||||
|
|
@@ -99,7 +99,7 @@ For custom Codex configuration, use `base_config_toml` and/or `additional_mcp_se | |||||||||||
| ```tf | ||||||||||||
| module "codex" { | ||||||||||||
| source = "registry.coder.com/coder-labs/codex/coder" | ||||||||||||
| version = "4.0.0" | ||||||||||||
| version = "4.1.0" | ||||||||||||
| # ... other variables ... | ||||||||||||
|
|
||||||||||||
| # Override default configuration | ||||||||||||
|
|
@@ -122,6 +122,61 @@ module "codex" { | |||||||||||
| > [!NOTE] | ||||||||||||
| > If no custom configuration is provided, the module uses secure defaults. The Coder MCP server is always included automatically. For containerized workspaces (Docker/Kubernetes), you may need `sandbox_mode = "danger-full-access"` to avoid permission issues. For advanced options, see [Codex config docs](https://github.com/openai/codex/blob/main/codex-rs/config.md). | ||||||||||||
|
|
||||||||||||
| ### AI Bridge Configuration | ||||||||||||
|
|
||||||||||||
| [AI Bridge](https://coder.com/docs/ai-coder/ai-bridge) is a centralized AI gateway that securely intermediates between users’ coding tools and AI providers, managing authentication, auditing, and usage attribution. | ||||||||||||
|
|
||||||||||||
| To the AI Bridge integration, first [set up AI Bridge](https://coder.com/docs/ai-coder/ai-bridge/setup) and set `enable_aibridge` to `true`. | ||||||||||||
|
|
||||||||||||
| #### Usage with tasks and AI Bridge | ||||||||||||
|
|
||||||||||||
| ```tf | ||||||||||||
| resource "coder_ai_task" "task" { | ||||||||||||
| count = data.coder_workspace.me.start_count | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This needs to be changed as well |
||||||||||||
| app_id = module.codex.task_app_id | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This needs to be changed here as well |
||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| data "coder_task" "me" {} | ||||||||||||
|
|
||||||||||||
| module "codex" { | ||||||||||||
| source = "registry.coder.com/coder-labs/codex/coder" | ||||||||||||
|
Comment on lines
+141
to
+142
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
The count needs to be included here since this is a reference for tasks |
||||||||||||
| version = "4.1.0" | ||||||||||||
| agent_id = coder_agent.example.id | ||||||||||||
| ai_prompt = data.coder_task.me.prompt | ||||||||||||
| workdir = "/home/coder/project" | ||||||||||||
| enable_aibridge = true | ||||||||||||
| } | ||||||||||||
| ``` | ||||||||||||
|
|
||||||||||||
| #### Standalone usage with AI Bridge | ||||||||||||
|
|
||||||||||||
| ```tf | ||||||||||||
| module "codex" { | ||||||||||||
| source = "registry.coder.com/coder-labs/codex/coder" | ||||||||||||
| version = "4.1.0" | ||||||||||||
| agent_id = coder_agent.example.id | ||||||||||||
| workdir = "/home/coder/project" | ||||||||||||
| enable_aibridge = true | ||||||||||||
| } | ||||||||||||
| ``` | ||||||||||||
|
|
||||||||||||
| This adds a new model_provider and a profile to the Codex configuration: | ||||||||||||
|
|
||||||||||||
| ```toml | ||||||||||||
| [model_providers.aibridge] | ||||||||||||
| name = "AI Bridge" | ||||||||||||
| base_url = "https://dev.coder.com/api/v2/aibridge/openai/v1" | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I would use an example url here since we dont need to expose our aibridge endpoint, and this uses the deployment url from whatever coder deployment its running from if im not mistaken |
||||||||||||
| env_key = "CODER_AIBRIDGE_SESSION_TOKEN" | ||||||||||||
| wire_api = "responses" | ||||||||||||
|
|
||||||||||||
| [profiles.aibridge] | ||||||||||||
| model_provider = "aibridge" | ||||||||||||
| model = "<model>" # as configured in the module input | ||||||||||||
| model_reasoning_effort = "<model_reasoning_effort>" # as configured in the module input | ||||||||||||
| ``` | ||||||||||||
|
|
||||||||||||
| Codex then runs with `--profile aibridge` | ||||||||||||
|
|
||||||||||||
| ## Troubleshooting | ||||||||||||
|
|
||||||||||||
| - Check installation and startup logs in `~/.codex-module/` | ||||||||||||
|
|
@@ -137,3 +192,4 @@ module "codex" { | |||||||||||
| - [Codex CLI Documentation](https://github.com/openai/codex) | ||||||||||||
| - [AgentAPI Documentation](https://github.com/coder/agentapi) | ||||||||||||
| - [Coder AI Agents Guide](https://coder.com/docs/tutorials/ai-agents) | ||||||||||||
| - [AI Bridge](https://coder.com/docs/ai-coder/ai-bridge) | ||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,6 +71,27 @@ variable "cli_app_display_name" { | |
| default = "Codex CLI" | ||
| } | ||
|
|
||
| variable "enable_aibridge" { | ||
| type = bool | ||
| description = "Use AI Bridge for Codex. https://coder.com/docs/ai-coder/ai-bridge" | ||
| default = false | ||
|
|
||
| validation { | ||
| condition = !(var.enable_aibridge && length(var.openai_api_key) > 0) | ||
| error_message = "openai_api_key cannot be provided when enable_aibridge is true. AI Bridge automatically authenticates the client using their Coder credentials." | ||
| } | ||
| } | ||
|
|
||
| variable "model_reasoning_effort" { | ||
| type = string | ||
| description = "The reasoning effort for the AI Bridge model. One of: none, low, medium, high. https://platform.openai.com/docs/guides/latest-model#lower-reasoning-effort" | ||
| default = "medium" | ||
| validation { | ||
| condition = contains(["none", "low", "medium", "high"], var.model_reasoning_effort) | ||
| error_message = "model_reasoning_effort must be one of: none, low, medium, high." | ||
| } | ||
| } | ||
|
|
||
| variable "install_codex" { | ||
| type = bool | ||
| description = "Whether to install Codex." | ||
|
|
@@ -115,8 +136,8 @@ variable "agentapi_version" { | |
|
|
||
| variable "codex_model" { | ||
| type = string | ||
| description = "The model for Codex to use. Defaults to gpt-5.1-codex-max." | ||
| default = "" | ||
| description = "The model for Codex to use. Defaults to gpt-5.2-codex." | ||
| default = "gpt-5.2-codex" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like it is not yet available for the API billing we use. So maybe use next best
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @matifali @DevelopmentCats imo, we should leave the default as empty and not mention this either
And make passing the model mandatory in the case of
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One issue that I notice with using these codex models with aibridge, is that the openai codex modules only support the Currently from what I can see aibridge does not currently log
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is fine. It will be supported by next release. We will release this until we bring the interception functionality
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is fine. It will be supported by next release. We will release this until we bring the interception functionality
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is fine. It will be supported by next release. We will release this until we bring the interception functionality |
||
| } | ||
|
|
||
| variable "pre_install_script" { | ||
|
|
@@ -155,12 +176,31 @@ resource "coder_env" "openai_api_key" { | |
| value = var.openai_api_key | ||
| } | ||
|
|
||
| resource "coder_env" "coder_aibridge_session_token" { | ||
| count = var.enable_aibridge ? 1 : 0 | ||
| agent_id = var.agent_id | ||
| name = "CODER_AIBRIDGE_SESSION_TOKEN" | ||
| value = data.coder_workspace_owner.me.session_token | ||
| } | ||
|
|
||
| locals { | ||
| workdir = trimsuffix(var.workdir, "/") | ||
| app_slug = "codex" | ||
| install_script = file("${path.module}/scripts/install.sh") | ||
| start_script = file("${path.module}/scripts/start.sh") | ||
| module_dir_name = ".codex-module" | ||
| aibridge_config = <<-EOF | ||
| [model_providers.aibridge] | ||
| name = "AI Bridge" | ||
| base_url = "${data.coder_workspace.me.access_url}/api/v2/aibridge/openai/v1" | ||
| env_key = "CODER_AIBRIDGE_SESSION_TOKEN" | ||
| wire_api = "responses" | ||
|
|
||
| [profiles.aibridge] | ||
| model_provider = "aibridge" | ||
| model = "${var.codex_model}" | ||
| model_reasoning_effort = "${var.model_reasoning_effort}" | ||
| EOF | ||
| } | ||
|
|
||
| module "agentapi" { | ||
|
|
@@ -196,6 +236,7 @@ module "agentapi" { | |
| ARG_CODEX_START_DIRECTORY='${local.workdir}' \ | ||
| ARG_CODEX_TASK_PROMPT='${base64encode(var.ai_prompt)}' \ | ||
| ARG_CONTINUE='${var.continue}' \ | ||
| ARG_ENABLE_AIBRIDGE='${var.enable_aibridge}' \ | ||
| /tmp/start.sh | ||
| EOT | ||
|
|
||
|
|
@@ -211,6 +252,8 @@ module "agentapi" { | |
| ARG_INSTALL='${var.install_codex}' \ | ||
| ARG_CODEX_VERSION='${var.codex_version}' \ | ||
| ARG_BASE_CONFIG_TOML='${base64encode(var.base_config_toml)}' \ | ||
| ARG_ENABLE_AIBRIDGE='${var.enable_aibridge}' \ | ||
| ARG_AIBRIDGE_CONFIG='${base64encode(var.enable_aibridge ? local.aibridge_config : "")}' \ | ||
| ARG_ADDITIONAL_MCP_SERVERS='${base64encode(var.additional_mcp_servers)}' \ | ||
| ARG_CODER_MCP_APP_STATUS_SLUG='${local.app_slug}' \ | ||
| ARG_CODEX_START_DIRECTORY='${local.workdir}' \ | ||
|
|
||

Uh oh!
There was an error while loading. Please reload this page.