Skip to content

Use API Key Authentication

Authenticate with model providers like OpenAI using API keys, either from environment variables or stored in secret managers.

QType YAML

auths:
  - type: api_key
    id: openai_auth
    api_key: ${OPENAI_KEY}
    host: https://api.openai.com

models:
  - type: Model
    id: gpt-4
    provider: openai
    model_id: gpt-4-turbo
    auth: openai_auth

Explanation

  • type: api_key: Specifies this is an API key-based authentication provider
  • api_key: The API key value, typically loaded from an environment variable using ${VAR_NAME} syntax
  • host: Base URL or domain of the provider (optional, some providers infer this)
  • auth: Reference to the auth provider by its ID when configuring models

Complete Example

id: 01_hello_world
description: My first QType application

auths:
  - type: api_key
    id: openai_auth
    api_key: ${OPENAI_KEY}
    host: https://api.openai.com

models:
  - type: Model
    id: gpt-4
    provider: openai
    model_id: gpt-4-turbo
    auth: openai_auth
    inference_params:
      temperature: 0.7

flows:
  - type: Flow
    id: simple_example
    variables:
      - id: question
        type: text
      - id: formatted_prompt
        type: text
      - id: answer
        type: text
    inputs:
      - question
    outputs:
      - answer
    steps:
      - id: format_prompt
        type: PromptTemplate
        template: "You are a helpful assistant. Answer the following question:\n{question}\n"
        inputs:
          - question
        outputs:
          - formatted_prompt

      - id: llm_step
        type: LLMInference
        model: gpt-4
        inputs:
          - formatted_prompt
        outputs:
          - answer

See Also