Skip to content
Discussion options

You must be logged in to vote

You can do this with a pre-function:

- name: pre-function
  config:
    rewrite:
      - |
        if not kong.request.get_header("X-Model") then
          local b = kong.request.get_body("application/json")

          if b and b.model then
            kong.service.request.set_header("X-Model", b.model)
          end
        end

Now set each of your "routes" to be on the same path e.g. paths: [ "~/chat/completions$" ] but route by header value e.g. x-model: gpt-4o

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@chobits
Comment options

chobits Jul 14, 2025
Collaborator

Comment options

You must be logged in to vote
0 replies
Answer selected by tysoekong
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
3 participants