Yandex Cloud
Search
Contact UsGet started
  • Pricing
  • Customer Stories
  • Documentation
  • Blog
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • AI for business
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Center for Technologies and Society
    • Yandex Cloud Partner program
  • Pricing
  • Customer Stories
  • Documentation
  • Blog
© 2025 Direct Cursus Technology L.L.C.
Yandex AI Studio
    • All guides
    • Disabling request logging
    • Getting an API key
      • Estimating prompt size in tokens
      • Sending a request in prompt mode
      • Sending a series of requests in chat mode
      • Sending an asynchronous request
      • Calling a function from a model
    • Image generation
    • Batch processing
    • About Yandex AI Studio
    • Yandex Workflows
    • Quotas and limits
    • Terms and definitions
  • Compatibility with OpenAI
  • Access management
  • Pricing policy
  • Audit Trails events
  • Public materials
  • Release notes

In this article:

  • Getting started
  • Build a chat
  1. Step-by-step guides
  2. Text generation
  3. Sending a series of requests in chat mode

How to build a chat with the Responses API

Written by
Yandex Cloud
Updated at October 28, 2025
  • Getting started
  • Build a chat

Getting startedGetting started

Python

Get API authentication credentials as described in Authentication with the Yandex AI Studio API.

Build a chatBuild a chat

Python
  1. Create a file named index.py and add the following code to it:

    import openai
    
    YANDEX_CLOUD_MODEL = "yandexgpt-lite"
    
    client = openai.OpenAI(
        api_key=YANDEX_CLOUD_API_KEY,
        base_url="https://rest-assistant.api.cloud.yandex.net/v1",
        project=YANDEX_CLOUD_FOLDER
    )
    
    previous_id = None # Saving the last response ID
    
    print("💬 Chat with GPT (enter 'exit' to exit)\n")
    
    while True:
        user_input = input("You: ")
        if user_input.lower() in ("exit", "quit"):
            print("Chat session ended.")
            break
    
        response = client.responses.create(
            model=f"gpt://{YANDEX_CLOUD_FOLDER}/{YANDEX_CLOUD_MODEL}",
            input=[{"role": "user", "content": user_input}],
            previous_response_id=previous_id  # Providing context, if any
        )
    
        # Saving the ID for the next step
        previous_id = response.id
    
        # Printing the agent's response
        print("Agent:", response.output_text)
    
  2. Save authentication data to environment variables:

    export YANDEX_CLOUD_FOLDER=<folder_ID>
    export YANDEX_CLOUD_API_KEY=<API_key>
    
  3. Run the file you created:

    python index.py
    

    Response example:

    💬 Chat with GPT (enter 'exit' to exit)
    
    You: Hi!
    Agent: Hi there! How can I help you?
    You: What exactly can you do?
    Agent: I can answer questions, help solve various problems, and provide information on various topics. For example, I can tell you about the weather, help with translating a text, suggest ideas, or just keep the conversation going. What are you interested in?
    You: Tell me a joke
    Agent: Why do programmers always have a cup of coffee? Because when they are working on a hard problem, they need to overclock their central processing unit... and the coffee helps them do it!
    You: Exit
    Chat session ended.
    

See alsoSee also

  • Common instance models
  • Examples of working with ML SDK on GitHub

Was the article helpful?

Previous
Sending a request in prompt mode
Next
Sending an asynchronous request
© 2025 Direct Cursus Technology L.L.C.