Overview

The Julep’s Open Responses API provides a straightforward way to interact with language models for quick, one-off interactions. This tutorial will guide you through leveraging the SDK to create and retrieve responses.

  • The Open Responses API requires self-hosting. See the installation guide below.
  • Being in Alpha, the API is subject to change. Check back frequently for updates.
  • For more context, see the OpenAI Responses API documentation.

API Key Configuration

  • RESPONSE_API_KEY is the API key that you set in the .env file.

Model Selection

  • While using models other than OpenAI, one might need to add the provider/ prefix to the model name.
  • For supported providers, see the LiteLLM Providers documentation.

Environment Setup

  • Add the relevant provider keys to the .env file to use their respective models.

Creating a Response

To generate a response using the OpenAI SDKs, you’ll use the create method. Here’s how to do it with OpenAI’s SDKs:

from openai import OpenAI

# Initialize the client with your Julep API key
openai_client = OpenAI(base_url="http://localhost:8080/", api_key="RESPONSE_API_KEY")

# Create a simple response
response = openai_client.responses.create(
    model="gpt-4o-mini",
    input="Think about this math problem and try to solve it: If a train leaves Chicago at 2pm traveling west at 60mph, and another train leaves Denver at 3pm traveling east at 75mph, and the distance between Chicago and Denver is 1000 miles, at what time will the trains meet?",
    tools=None, # Optional, defaults to None
)

# Extract and print the generated text
print("Generated response:", response.output[0].content[0].text)

Follow the example below to see a sample response from the Responses API.

Using Function Calling Tools

response = openai_client.responses.create(
    model="gpt-4o-mini",
    input="What's the weather in New York City?",
    tools=[{
        "type": "function",
        "name": "get_weather",
        "description": "Get the current weather in a location",
        "parameters": {
            "type": "object",
            "properties": {
                "location": {
                    "type": "string",
                    "description": "The city and state, e.g. New York, NY"
                },
                "unit": {
                    "type": "string",
                    "enum": ["celsius", "fahrenheit"],
                    "description": "The unit of temperature to use"
                }
            },
            "required": ["location"]
        }
    }]
)

# The output will include both the text response and any tool calls that were made

Follow the example below to see a sample response from the Responses API.

  • Please note that the model will generate a response with the Function tool call with the required arguments which can be found in the Response object. As a user, you need to manually run the custom function tool call with the required arguments to get the output and then feed it back to the model along with the original responses and the tool call to get the final response.
  • To learn more about Function Calling, please refer to the OpenAI Function Calling section.

Using Web Search Tool

from openai import OpenAI

openai_client = OpenAI(base_url="http://localhost:8080/", api_key="RESPONSE_API_KEY")

response = openai_client.responses.create(
    model="gpt-4o-mini",
    tools=[{"type": "web_search_preview"}],
    input="What was a positive news story from today?",
)

Follow the example below to see a sample response from the Responses API.

Currently our Responses API only supports the following functionality:

  • Text input
  • Image input
  • Function calling
  • Reasoning
  • Web search

We are working on adding support for more functionality in the future.

Retrieving a Response

from openai import OpenAI

openai_client = OpenAI(base_url="http://localhost:8080/", api_key="RESPONSE_API_KEY")
response = openai_client.responses.retrieve(
    response_id="response_id_here"
)
print("Retrieved response:", response.output[0].content[0].text)

Follow the example below to see a sample response from the Responses API.

Check out the API reference or SDK reference (Python or JavaScript) for more details on different operations you can perform with the Responses API.

Next Steps