Repository: sst/opencode
File: packages/opencode/src/provider/provider.ts (TypeScript)

Code before:
            "x-title": "opencode",
          },
        },
      }
    },
    "google-vertex": async (provider) => {
      const project =
        provider.options?.project ??
        Env.get("GOOGLE_CLOUD_PROJECT") ??
        Env.get("GCP_PROJECT") ??
        Env.get("GCLOUD_PROJECT")

      const location =
        provider.options?.location ?? Env.get("GOOGLE_CLOUD_LOCATION") ?? Env.get("VERTEX_LOCATION") ?? "us-central1"

      const autoload = Boolean(project)
      if (!autoload) return { autoload: false }

      return {
        autoload: true,
        options: {
          project,
          location,
          baseURL:
            location === "global"
              ? `https://aiplatform.googleapis.com/v1beta1/projects/${project}/locations/${location}/endpoints/openapi`
              : `https://${location}-aiplatform.googleapis.com/v1beta1/projects/${project}/locations/${location}/endpoints/openapi`,
          fetch: async (input: RequestInfo | URL, init?: RequestInit) => {
            const { GoogleAuth } = await import(await BunProc.install("google-auth-library"))
            const auth = new GoogleAuth()
            const client = await auth.getApplicationDefault()
            const credentials = await client.credential
            const token = await credentials.getAccessToken()

            const headers = new Headers(init?.headers)
            headers.set("Authorization", `Bearer ${token.token}`)

            return fetch(input, { ...init, headers })
          },
        },
        async getModel(sdk: any, modelID: string) {
          const id = String(modelID).trim()
          // For official SDK, it expects languageModel(id). For openai-compatible (via openapi), it likely expects just the ID or similar,
          // but relying on the defaults in getSDK should handle the sdk() call if it's not the official one.
          // Yet, looking at the previous implementations:
          // vertex: sdk.languageModel(id)
          // vertex-openapi: sdk(modelID)
          // We need to know which SDK we are dealing with.
          // However, getModel is called with the *instantiated* SDK.
          // If it's @ai-sdk/google-vertex, it has .languageModel
          // If it's @ai-sdk/openai-compatible, it is a function.

Review comment (suggestion):
```suggestion
              ? `https://aiplatform.googleapis.com/v1/projects/${project}/locations/${location}/endpoints/openapi`
```

Code after:
                regionPrefix = "au"
                modelID = `${regionPrefix}.${modelID}`
              } else if (isTokyoRegion) {
                // Tokyo region uses jp. prefix for cross-region inference
                const modelRequiresPrefix = ["claude", "nova-lite", "nova-micro", "nova-pro"].some((m) =>
                  modelID.includes(m),
                )
                if (modelRequiresPrefix) {
                  regionPrefix = "jp"
                  modelID = `${regionPrefix}.${modelID}`
                }
              } else {
                // Other APAC regions use apac. prefix
                const modelRequiresPrefix = ["claude", "nova-lite", "nova-micro", "nova-pro"].some((m) =>
                  modelID.includes(m),
                )
                if (modelRequiresPrefix) {
                  regionPrefix = "apac"
                  modelID = `${regionPrefix}.${modelID}`
                }
              }
              break
            }
          }

          return sdk.languageModel(modelID)
        },
      }
    },
    openrouter: async () => {
      return {
        autoload: false,
        options: {
          headers: {
            "HTTP-Referer": "https://opencode.ai/",
            "X-Title": "opencode",
          },
        },
      }
    },
    vercel: async () => {
      return {
        autoload: false,
        options: {
          headers: {
            "http-referer": "https://opencode.ai/",
            "x-title": "opencode",
          },
        },
      }
    },