Env variables in the API Definition


I’m doing my first steps with Tyk and stuck with a simple task.

I use docker-compose for development to run 2 services: Tyk API Gateway and Test service.
Request to http://localhost:8080/test should be proxied to Test service host, defined in docker-compose config (http://test-service:3000).


  "name": "Test",
  "use_keyless": true,
  "version_data": {
    "not_versioned": true,
    "versions": {
      "Default": {
        "name": "Default",
        "expires": ""
  "proxy": {
    "preserve_host_header": false,
    "listen_path": "/test",
    "target_url": "http://test-service:3000",
    "strip_listen_path": true
  "active": true,

But host and port for target_url are hardcoded in thia case. If I need to change it for some reason - I need to make changes in Tyk API definition file. If I want to deploy my code to the cloud - I need to worry about the same service host.

I read about the service_discovery option. But anyway I need to path query_endpoint for it which depends on the environment.

I found a similar question without an answer: Use environment variable for jwt_source in API def JSON

So, what is a workaround?

Maybe there is something like $tyk_context or $tyk_meta for API definition and I just cannot find it?
Or another approach…
I thought about storing definitions as templates and process them on start with ENV variables. Using sed, for example. But it looks not elegantly.

1 Like

Found issue about this problem Environment Migration with Context Variable · Issue #2476 · TykTechnologies/tyk · GitHub

1 Like

Looking for same feature since we can’t hardcode variables in API definition files and using SED to replace text isn’t elegant.

Edit: Kv store for secrets in configuration by adelowo · Pull Request #2465 · TykTechnologies/tyk · GitHub has been merged but documentation hasn’t yet updated.