Skip to content

SDK variables: optional env-var fallback (IR envVar) + support in Go/C#/Ruby/PHP generators (Twilio subaccount routing) #18048

Open

Description

@devin-ai-integration

Summary

Twilio (fern-demo/twilio-core-fern-config) needs the official-SDK "act on behalf of a subaccount" behaviour: parent-account credentials + a single client-level account SID that is substituted into every v2010 {AccountSid} path, defaulting to the parent account when not set (twilio(sid, token, { accountSid }), Client(sid, token, account_sid=), Twilio.init(sid, token, accountSid)).

Fern already has SDK variables (x-fern-sdk-variables / x-fern-sdk-variable, Fern definition variables:), but two gaps blocked using them for this:

  1. No fallback – a variable was always a required constructor argument. Parent-account callers would have to pass targetAccountSid explicitly; the official SDKs default it to the auth account SID (TWILIO_ACCOUNT_SID).
  2. Only TypeScript, Python and Java implemented IR variables – Go, C#, Ruby (v2) and PHP silently ignored x-fern-sdk-variable and kept the path parameter on every method.

Design

  • IR VariableDeclaration.envVar?: string (IR 67.29.0).
  • Fern definition: variables: { targetAccountSid: { type: string, env: TWILIO_ACCOUNT_SID } }; OpenAPI: x-fern-sdk-variables: { targetAccountSid: { type: string, x-fern-env: TWILIO_ACCOUNT_SID } }; bind with x-fern-sdk-variable: targetAccountSid on path params.
  • Generators: a string variable with envVar becomes an optional client option; explicit value > environment variable; if a bound endpoint is called with neither set, the SDK raises a clear "<variable> is required" error. Variables without envVar stay required. Bound path parameters are removed from method signatures / request types / reference docs; one value per client (matches official Twilio semantics).

PRs

Follow-up (Twilio side)

  • fern-demo/twilio-core-fern-config#157 adds targetAccountSid to the core v2010 override (191 {AccountSid} path params bound; account-management {Sid} paths stay explicit).
  • After the generator releases above, bump the pinned generator versions in that repo and regenerate/verify all 7 SDKs (TS targetAccountSid, Python target_account_sid, Java .targetAccountSid(...), Go option.WithTargetAccountSid(...), C# ClientOptions.TargetAccountSid, Ruby target_account_sid:, PHP targetAccountSid:).

Not in scope: per-call override of a bound variable alongside the client default (the official SDKs' client.api.v2010.accounts(sid)... escape hatch) — Fern drops the parameter from the method once it is bound.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions